///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select curves to apply linear tags"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); go.EnableSubObjectSelect(false); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); EstimatorTagForm form = new EstimatorTagForm(); form.m_str_title = "Add Linear Tags"; form.m_str_prompt = "Select one or more linear tags."; form.m_type = EstimatorTag.tag_type.linear_tag; DialogResult rc = form.ShowDialog(); if (rc == DialogResult.Cancel) return IRhinoCommand.result.cancel; List<string> tag_strings = new List<string>(form.m_selected_tags.Count); EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn; int i = 0; for (i = 0; i < form.m_selected_tags.Count; i++) { int index = form.m_selected_tags[i]; tag_strings.Add(plugin.m_tag_table[index].Id()); } for (i = 0; i < go.ObjectCount(); i++) EstimatorHelpers.AddData(go.Object(i).Object(), tag_strings.ToArray()); return IRhinoCommand.result.success; }
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects for Z analysis"); go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object ); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); int count = 0; for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject obj = go.Object(i).Object(); if (null == obj) continue; if (obj.InAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID)) // This object is already in Z analysis mode continue; if (obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, true)) // A new object is in Z analysis mode count++; } context.m_doc.Redraw(); RhUtil.RhinoApp().Print(string.Format("{0} objects were put into Z-Analysis mode.\n", count)); return IRhinoCommand.result.success; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select solid meshes for volume calculation"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object); go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh); go.EnableSubObjectSelect(false); go.EnableGroupSelect(); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } List <IOnMesh> meshes = new List <IOnMesh>(); for (int i = 0; i < go.ObjectCount(); i++) { IOnMesh mesh = go.Object(i).Mesh(); if (mesh != null) { meshes.Add(mesh); } } if (meshes.Count == 0) { return(IRhinoCommand.result.nothing); } OnBoundingBox bbox = new OnBoundingBox(); for (int i = 0; i < meshes.Count; i++) { meshes[i].GetBoundingBox(ref bbox, 1); } On3dPoint base_point = bbox.Center(); double total_volume = 0.0; double total_error_estimate = 0.0; string msg; for (int i = 0; i < meshes.Count; i++) { double error_estimate = 0.0; double volume = meshes[i].Volume(base_point, ref error_estimate); msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate); RhUtil.RhinoApp().Print(msg); total_volume += volume; total_error_estimate += error_estimate; } msg = string.Format("Total volume = {0:f} (+/- {1:f})\n", total_volume, total_error_estimate); RhUtil.RhinoApp().Print(msg); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select solid meshes for volume calculation"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object); go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh); go.EnableSubObjectSelect(false); go.EnableGroupSelect(); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); List<IOnMesh> meshes = new List<IOnMesh>(); for (int i = 0; i < go.ObjectCount(); i++) { IOnMesh mesh = go.Object(i).Mesh(); if (mesh != null) meshes.Add(mesh); } if (meshes.Count == 0) return IRhinoCommand.result.nothing; OnBoundingBox bbox = new OnBoundingBox(); for (int i = 0; i < meshes.Count; i++) meshes[i].GetBoundingBox(ref bbox, 1); On3dPoint base_point = bbox.Center(); double total_volume = 0.0; double total_error_estimate = 0.0; string msg; for (int i = 0; i < meshes.Count; i++) { double error_estimate = 0.0; double volume = meshes[i].Volume(base_point, ref error_estimate); msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate); RhUtil.RhinoApp().Print(msg); total_volume += volume; total_error_estimate += error_estimate; } msg = string.Format("Total volume = {0:f} (+/- {1:f})\n", total_volume, total_error_estimate); RhUtil.RhinoApp().Print(msg); return IRhinoCommand.result.success; }
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects for Z analysis"); go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object ); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } int count = 0; for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject obj = go.Object(i).Object(); if (null == obj) { continue; } if (obj.InAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID)) { // This object is already in Z analysis mode continue; } if (obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, true)) { // A new object is in Z analysis mode count++; } } context.m_doc.Redraw(); RhUtil.RhinoApp().Print(string.Format("{0} objects were put into Z-Analysis mode.\n", count)); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select curves to apply linear tags"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); go.EnableSubObjectSelect(false); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } EstimatorTagForm form = new EstimatorTagForm(); form.m_str_title = "Add Linear Tags"; form.m_str_prompt = "Select one or more linear tags."; form.m_type = EstimatorTag.tag_type.linear_tag; DialogResult rc = form.ShowDialog(); if (rc == DialogResult.Cancel) { return(IRhinoCommand.result.cancel); } List <string> tag_strings = new List <string>(form.m_selected_tags.Count); EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn; int i = 0; for (i = 0; i < form.m_selected_tags.Count; i++) { int index = form.m_selected_tags[i]; tag_strings.Add(plugin.m_tag_table[index].Id()); } for (i = 0; i < go.ObjectCount(); i++) { EstimatorHelpers.AddData(go.Object(i).Object(), tag_strings.ToArray()); } return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects to apply item tag"); go.EnableSubObjectSelect(false); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); EstimatorTagForm form = new EstimatorTagForm(); form.m_str_title = "Add Item Tag"; form.m_str_prompt = "Select an item tag."; form.m_type = EstimatorTag.tag_type.item_tag; DialogResult rc = form.ShowDialog(); if (rc == DialogResult.Cancel) return IRhinoCommand.result.cancel; List<string> tag_strings = new List<string>(form.m_selected_tags.Count); EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn; int i = 0; for (i = 0; i < form.m_selected_tags.Count; i++) { int index = form.m_selected_tags[i]; tag_strings.Add(plugin.m_tag_table[index].Id()); } for (i = 0; i < go.ObjectCount(); i++) { EstimatorHelpers.RemoveAllData(go.Object(i).Object()); EstimatorHelpers.AddData(go.Object(i).Object(), tag_strings.ToArray()); } return IRhinoCommand.result.success; }
/// <summary> /// This gets called when when the user runs this command. /// </summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Select objects to animate MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects to animate"); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } // Select path curve MRhinoGetObject gc = new MRhinoGetObject(); gc.SetCommandPrompt("Select path curve"); gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve); gc.EnableDeselectAllBeforePostSelect(false); gc.GetObjects(1, 1); if (gc.CommandResult() != IRhinoCommand.result.success) { return(gc.CommandResult()); } // Get the curve IOnCurve crv = gc.Object(0).Curve(); if (null == crv) { return(IRhinoCommand.result.failure); } // Create an array of normalized curve parameters List <double> slist = new List <double>(m_max_steps); for (int i = 0; i < m_max_steps; i++) { double s = (double)i / ((double)m_max_steps - 1); slist.Add(s); } // Get the real parameters along the curve double[] tlist = new double[m_max_steps]; if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist)) { return(IRhinoCommand.result.failure); } // Create the display conduit SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit(); // Get points along curve On3dPoint start = new On3dPoint(crv.PointAtStart()); List <On3dPoint> plist = new List <On3dPoint>(tlist.Length); for (int i = 0; i < m_max_steps; i++) { On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i])); plist.Add(pt); } // Hide objects and add them to conduit's object array for (int i = 0; i < go.ObjectCount(); i++) { MRhinoObjRef objref = go.Object(i); context.m_doc.HideObject(objref); conduit.m_objects.Add(objref.Object()); } // Do animation... conduit.Enable(); for (int i = 0; i < m_max_steps; i++) { On3dVector v = plist[i] - start; conduit.m_xform.Translation(v); context.m_doc.Redraw(); Thread.Sleep(100); } for (int i = m_max_steps - 1; i >= 0; i--) { On3dVector v = plist[i] - start; conduit.m_xform.Translation(v); if (0 != i) { context.m_doc.Redraw(); Thread.Sleep(100); } } conduit.Disable(); // Show hidden objects for (int i = 0; i < go.ObjectCount(); i++) { MRhinoObjRef objref = go.Object(i); context.m_doc.ShowObject(objref); } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
/// <summary> /// This gets called when when the user runs this command. /// </summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Select objects to animate MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects to animate"); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); // Select path curve MRhinoGetObject gc = new MRhinoGetObject(); gc.SetCommandPrompt("Select path curve"); gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve); gc.EnableDeselectAllBeforePostSelect(false); gc.GetObjects(1, 1); if (gc.CommandResult() != IRhinoCommand.result.success) return gc.CommandResult(); // Get the curve IOnCurve crv = gc.Object(0).Curve(); if (null == crv ) return IRhinoCommand.result.failure; // Create an array of normalized curve parameters List<double> slist = new List<double>(m_max_steps); for (int i = 0; i < m_max_steps; i++ ) { double s = (double)i / ( (double)m_max_steps - 1 ); slist.Add(s); } // Get the real parameters along the curve double[] tlist = new double[m_max_steps]; if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist)) return IRhinoCommand.result.failure; // Create the display conduit SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit(); // Get points along curve On3dPoint start = new On3dPoint(crv.PointAtStart()); List<On3dPoint> plist = new List<On3dPoint>(tlist.Length); for (int i = 0; i < m_max_steps; i++) { On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i])); plist.Add(pt); } // Hide objects and add them to conduit's object array for (int i = 0; i < go.ObjectCount(); i++ ) { MRhinoObjRef objref = go.Object(i); context.m_doc.HideObject(objref); conduit.m_objects.Add(objref.Object()); } // Do animation... conduit.Enable(); for (int i = 0; i < m_max_steps; i++) { On3dVector v = plist[i] - start; conduit.m_xform.Translation(v); context.m_doc.Redraw(); Thread.Sleep(100); } for (int i = m_max_steps - 1; i >= 0; i--) { On3dVector v = plist[i] - start; conduit.m_xform.Translation(v); if (0 != i) { context.m_doc.Redraw(); Thread.Sleep(100); } } conduit.Disable(); // Show hidden objects for (int i = 0; i < go.ObjectCount(); i++) { MRhinoObjRef objref = go.Object(i); context.m_doc.ShowObject(objref); } context.m_doc.Redraw(); return IRhinoCommand.result.success; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { Model.globalContext = context; // get file info after it has been loaded into memory. Model.txtFilename = context.m_doc.GetPathName(); Model.txtTitle = context.m_doc.GetTitle(); // http://wiki.mcneel.com/developer/sdksamples/meshvolume MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt( "Select solid meshes for volume calculation" ); go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object ); go.SetGeometryAttributeFilter( IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh ); go.EnableSubObjectSelect(false); go.EnableGroupSelect(); go.GetObjects( 1, 0 ); if( go.CommandResult() != IRhinoCommand.result.success ) return go.CommandResult(); List<IOnMesh> meshes = new List<IOnMesh>(); for( int i = 0; i < go.ObjectCount(); i++ ) { IOnMesh mesh = go.Object(i).Mesh(); if( mesh != null ) meshes.Add( mesh ); } if( meshes.Count == 0 ) return IRhinoCommand.result.nothing; OnBoundingBox bbox = new OnBoundingBox(); for( int i = 0; i < meshes.Count; i++ ) meshes[i].GetBoundingBox( ref bbox, 1 ); On3dPoint base_point = bbox.Center(); double total_volume = 0.0; double total_error_estimate = 0.0; string msg; for( int i = 0; i < meshes.Count; i++ ) { double error_estimate = 0.0; double volume = meshes[i].Volume( base_point, ref error_estimate ); msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n",i,volume,error_estimate); RhUtil.RhinoApp().Print( msg ); total_volume += volume; total_error_estimate += error_estimate; } msg = string.Format("Total volume = {0:f} (+/- {1:f})\n", total_volume, total_error_estimate); RhUtil.RhinoApp().Print( msg ); return IRhinoCommand.result.success; /* System.Guid id = CsDockingDialogDockBar.ID(); bool bVisible = RMA.UI.MRhinoDockBarManager.IsDockBarVisible(id); string prompt; if (bVisible) prompt = string.Format("{0} window is visible. New value", EnglishCommandName()); else prompt = string.Format("{0} window is hidden. New value", EnglishCommandName()); MRhinoGetOption go = new MRhinoGetOption(); go.SetCommandPrompt(prompt); int h_option = go.AddCommandOption(new MRhinoCommandOptionName("Hide")); int s_option = go.AddCommandOption(new MRhinoCommandOptionName("Show")); int t_option = go.AddCommandOption(new MRhinoCommandOptionName("Toggle")); go.GetOption(); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); IRhinoCommandOption opt = go.Option(); if (opt == null) return IRhinoCommand.result.failure; int option_index = opt.m_option_index; if (h_option == option_index) { if (bVisible) RMA.UI.MRhinoDockBarManager.ShowDockBar(id, false, false); } else if (s_option == option_index) { if (!bVisible) RMA.UI.MRhinoDockBarManager.ShowDockBar(id, true, false); } else if (t_option == option_index) { if (bVisible) RMA.UI.MRhinoDockBarManager.ShowDockBar(id, false, false); else RMA.UI.MRhinoDockBarManager.ShowDockBar(id, true, false); } return IRhinoCommand.result.success;*/ }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Step 1, select objects to include in the instance definition MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects to define block"); go.EnableReferenceObjectSelect(false); go.EnableSubObjectSelect(false); go.EnableGroupSelect(true); // Phantoms, grips, lights, etc., cannot be in instance definitions. uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object ); uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object; go.SetGeometryFilter(geometry_filter); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } // Step 2, select base point MRhinoGetPoint gp = new MRhinoGetPoint(); gp.SetCommandPrompt("Block base point"); gp.GetPoint(); if (gp.CommandResult() != IRhinoCommand.result.success) { return(gp.CommandResult()); } On3dPoint base_point = gp.Point(); // Step 3, get instance definition name MRhinoGetString gs = new MRhinoGetString(); gs.SetCommandPrompt("Block definition name"); gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc)); gs.GetString(); if (gs.CommandResult() != IRhinoCommand.result.success) { return(gs.CommandResult()); } string idef_name = gs.String().Trim(); if (string.IsNullOrEmpty(idef_name)) { return(IRhinoCommand.result.nothing); } // Step 4, verify objects int found_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name); List <IRhinoObject> objects = new List <IRhinoObject>(); bool bQuietly = context.IsInteractive() ? false : true; for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject obj = go.Object(i).Object(); if (obj == null) { continue; } // Probably don't need to do this... if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType())) { continue; } if (obj.ObjectType() == IOn.object_type.instance_reference) { IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj); if (iref_obj != null) { if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0) { if (!bQuietly) { RhUtil.RhinoApp().Print("Unable to create block.\n"); } return(IRhinoCommand.result.failure); } } } objects.Add(obj); } // Step 5, create instance definition OnInstanceDefinition idef = new OnInstanceDefinition(); idef.SetName(idef_name); int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly); if (idef_index < 0) { return(IRhinoCommand.result.failure); } // Step 6, create the instance reference OnXform xform = new OnXform(); xform.Translation(base_point - new On3dPoint(OnUtil.On_origin)); IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform); if (inst_obj != null) { inst_obj.Select(true); } else { if (!bQuietly) { RhUtil.RhinoApp().Print("Error creating block.\n"); } return(IRhinoCommand.result.failure); } // Step 7, delete existing geometry for (int i = 0; i < objects.Count; i++) { context.m_doc.DeleteObject(new MRhinoObjRef(objects[i])); } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Step 1, select objects to include in the instance definition MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects to define block"); go.EnableReferenceObjectSelect(false); go.EnableSubObjectSelect(false); go.EnableGroupSelect(true); // Phantoms, grips, lights, etc., cannot be in instance definitions. uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object ); uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object; go.SetGeometryFilter(geometry_filter); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) return go.CommandResult(); // Step 2, select base point MRhinoGetPoint gp = new MRhinoGetPoint(); gp.SetCommandPrompt("Block base point"); gp.GetPoint(); if (gp.CommandResult() != IRhinoCommand.result.success) return gp.CommandResult(); On3dPoint base_point = gp.Point(); // Step 3, get instance definition name MRhinoGetString gs = new MRhinoGetString(); gs.SetCommandPrompt("Block definition name"); gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc)); gs.GetString(); if (gs.CommandResult() != IRhinoCommand.result.success) return gs.CommandResult(); string idef_name = gs.String().Trim(); if (string.IsNullOrEmpty(idef_name)) return IRhinoCommand.result.nothing; // Step 4, verify objects int found_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name); List<IRhinoObject> objects = new List<IRhinoObject>(); bool bQuietly = context.IsInteractive() ? false : true; for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject obj = go.Object(i).Object(); if (obj == null) continue; // Probably don't need to do this... if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType())) continue; if (obj.ObjectType() == IOn.object_type.instance_reference) { IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj); if (iref_obj != null) { if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0) { if (!bQuietly) RhUtil.RhinoApp().Print("Unable to create block.\n"); return IRhinoCommand.result.failure; } } } objects.Add(obj); } // Step 5, create instance definition OnInstanceDefinition idef = new OnInstanceDefinition(); idef.SetName(idef_name); int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly); if (idef_index < 0) return IRhinoCommand.result.failure; // Step 6, create the instance reference OnXform xform = new OnXform(); xform.Translation(base_point - new On3dPoint(OnUtil.On_origin)); IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform); if (inst_obj != null) { inst_obj.Select(true); } else { if (!bQuietly) RhUtil.RhinoApp().Print("Error creating block.\n"); return IRhinoCommand.result.failure; } // Step 7, delete existing geometry for (int i = 0; i < objects.Count; i++) context.m_doc.DeleteObject(new MRhinoObjRef(objects[i])); context.m_doc.Redraw(); return IRhinoCommand.result.success; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { int nValue = _nValue; double dValue = _dValue; MRhinoGetObject go = new MRhinoGetObject(); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); go.EnableGroupSelect(true); go.EnableSubObjectSelect(false); go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.EnableDeselectAllBeforePostSelect(false); bool bHavePreselectedObjects = false; for (; ;) { go.ClearCommandOptions(); int dOptionIndex = go.AddCommandOptionNumber( new MRhinoCommandOptionName("Double"), new MRhinoGet.DoubleOption(dValue), "Double value", false, 0.1, 99.9 ); int nOptionIndex = go.AddCommandOptionInteger( new MRhinoCommandOptionName("Integer"), new MRhinoGet.IntegerOption(nValue), "Integer value", 1, 99 ); IRhinoGet.result res = go.GetObjects(1, 0); if (res == IRhinoGet.result.option) { IRhinoCommandOption commandOption = go.Option(); if (null != commandOption) { int optionIndex = commandOption.m_option_index; if (optionIndex == nOptionIndex) { nValue = (int)commandOption.m_number_option_value; } else if (optionIndex == dOptionIndex) { dValue = commandOption.m_number_option_value; } } go.EnablePreSelect(false); continue; } else if (res != IRhinoGet.result.@object) { return(IRhinoCommand.result.cancel); } if (go.ObjectsWerePreSelected()) { bHavePreselectedObjects = true; go.EnablePreSelect(false); continue; } break; } if (bHavePreselectedObjects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } context.m_doc.Redraw(); } int objectCount = go.ObjectCount(); _dValue = dValue; _nValue = nValue; RhUtil.RhinoApp().Print(string.Format("Select object count = {0}\n", objectCount)); RhUtil.RhinoApp().Print(string.Format("Value of double = {0}\n", _dValue)); RhUtil.RhinoApp().Print(string.Format("Value of integer = {0}\n", _nValue)); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { int nValue = _nValue; double dValue = _dValue; MRhinoGetObject go = new MRhinoGetObject(); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); go.EnableGroupSelect(true); go.EnableSubObjectSelect(false); go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.EnableDeselectAllBeforePostSelect(false); bool bHavePreselectedObjects = false; for (; ; ) { go.ClearCommandOptions(); int dOptionIndex = go.AddCommandOptionNumber( new MRhinoCommandOptionName("Double"), new MRhinoGet.DoubleOption(dValue), "Double value", false, 0.1, 99.9 ); int nOptionIndex = go.AddCommandOptionInteger( new MRhinoCommandOptionName("Integer"), new MRhinoGet.IntegerOption(nValue), "Integer value", 1, 99 ); IRhinoGet.result res = go.GetObjects(1, 0); if (res == IRhinoGet.result.option) { IRhinoCommandOption commandOption = go.Option(); if (null != commandOption) { int optionIndex = commandOption.m_option_index; if (optionIndex == nOptionIndex) nValue = (int)commandOption.m_number_option_value; else if (optionIndex == dOptionIndex) dValue = commandOption.m_number_option_value; } go.EnablePreSelect(false); continue; } else if (res != IRhinoGet.result.@object) return IRhinoCommand.result.cancel; if (go.ObjectsWerePreSelected()) { bHavePreselectedObjects = true; go.EnablePreSelect(false); continue; } break; } if (bHavePreselectedObjects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) rhinoObject.Select(false); } context.m_doc.Redraw(); } int objectCount = go.ObjectCount(); _dValue = dValue; _nValue = nValue; RhUtil.RhinoApp().Print(string.Format("Select object count = {0}\n", objectCount)); RhUtil.RhinoApp().Print(string.Format("Value of double = {0}\n", _dValue)); RhUtil.RhinoApp().Print(string.Format("Value of integer = {0}\n", _nValue)); return IRhinoCommand.result.success; }