protected override Result RunCommand(RhinoDoc doc, RunMode mode) { SampleCsGetMultiplePointsConduit conduit = new SampleCsGetMultiplePointsConduit(); conduit.Enabled = true; Rhino.Commands.Result rc = Result.Nothing; Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); while (true) { if (0 == conduit.PointCount) { gp.SetCommandPrompt("Location of point object."); gp.AcceptNothing(false); gp.ClearCommandOptions(); } else { gp.SetCommandPrompt("Location of point object. Press Enter when done"); gp.AcceptNothing(true); gp.AddOption("Undo"); } Rhino.Input.GetResult res = gp.Get(); if (res == Rhino.Input.GetResult.Point) { conduit.AddPoint(gp.Point()); doc.Views.Redraw(); } else if (res == Rhino.Input.GetResult.Option) { conduit.RemoveLastPoint(); doc.Views.Redraw(); } else if (res == Rhino.Input.GetResult.Nothing) { rc = Rhino.Commands.Result.Success; break; } else { rc = Rhino.Commands.Result.Cancel; break; } } if (rc == Result.Success && conduit.PointCount > 0) { doc.Objects.AddPoints(conduit.Points); } conduit.Enabled = false; doc.Views.Redraw(); return(rc); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Display.RhinoView view = doc.Views.ActiveView; if (null == view) { return(Result.Failure); } Rhino.Display.RhinoViewport viewport = view.ActiveViewport; Rhino.Display.DisplayModeDescription currentDisplayMode = viewport.DisplayMode; Rhino.RhinoApp.WriteLine("Viewport in {0} display.", currentDisplayMode.EnglishName); Rhino.Display.DisplayModeDescription[] displayModes = Rhino.Display.DisplayModeDescription.GetDisplayModes(); Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Select new display mode"); go.AcceptNothing(true); foreach (Rhino.Display.DisplayModeDescription displayMode in displayModes) { string displayName = FormatValidDisplayName(displayMode.EnglishName); go.AddOption(displayName); } Rhino.Input.GetResult rc = go.Get(); switch (rc) { case Rhino.Input.GetResult.Option: { int optionIndex = go.Option().Index; if (optionIndex > 0 && optionIndex <= displayModes.Length) { Rhino.Display.DisplayModeDescription newDisplayMode = displayModes[optionIndex - 1]; if (newDisplayMode.Id != currentDisplayMode.Id) { viewport.DisplayMode = newDisplayMode; view.Redraw(); Rhino.RhinoApp.WriteLine("Viewport set to {0} display.", viewport.DisplayMode.EnglishName); } } } break; case Rhino.Input.GetResult.Cancel: return(Result.Cancel); default: break; } return(Result.Success); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { // Input interval var input = new Rhino.Input.Custom.GetNumber(); // Select surface var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select points"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Point; Rhino.Input.GetResult res = go.GetMultiple(1, 0); if (res == Rhino.Input.GetResult.Nothing) { return(Rhino.Commands.Result.Failure); } RhinoApp.WriteLine("Points {0} were selected", go.ObjectCount); try { SaveFileDialog dialog = new SaveFileDialog(); dialog.FileName = "PointFile.xyz"; dialog.Filter = "XYZ file|*.xyz|text file|*.txt"; dialog.Title = "Save point cloud file"; dialog.ShowDialog(); if (dialog.FileName == "") { return(Rhino.Commands.Result.Failure); } FileStream fileStream = (System.IO.FileStream)dialog.OpenFile(); // new FileStream(@"C:\Users\KTW\Documents\PointFile.xyz", FileMode.Create, FileAccess.Write); StreamWriter writer = new StreamWriter(fileStream); for (int i = 0; i < go.ObjectCount; i++) { Rhino.Geometry.Point pt = go.Object(i).Point(); Rhino.Geometry.Point3d pt3d = pt.Location; string text = pt3d.X + " " + pt3d.Y + " " + pt3d.Z; writer.WriteLine(text); } RhinoApp.WriteLine("File was saved"); fileStream.Close(); } catch (Exception e) { RhinoApp.WriteLine("{0}", e.Message); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result CommandLineOptions(Rhino.RhinoDoc doc) { // For this example we will use a GetPoint class, but all of the custom // "Get" classes support command line options. Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("GetPoint with options"); // set up the options Rhino.Input.Custom.OptionInteger intOption = new Rhino.Input.Custom.OptionInteger(1, 1, 99); Rhino.Input.Custom.OptionDouble dblOption = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9); Rhino.Input.Custom.OptionToggle boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On"); string[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" }; gp.AddOptionInteger("Integer", ref intOption); gp.AddOptionDouble("Double", ref dblOption); gp.AddOptionToggle("Boolean", ref boolOption); int listIndex = 3; int opList = gp.AddOptionList("List", listValues, listIndex); while (true) { // perform the get operation. This will prompt the user to input a point, but also // allow for command line options defined above Rhino.Input.GetResult get_rc = gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } if (get_rc == Rhino.Input.GetResult.Point) { doc.Objects.AddPoint(gp.Point()); doc.Views.Redraw(); Rhino.RhinoApp.WriteLine("Command line option values are"); Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue); Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue); Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue); Rhino.RhinoApp.WriteLine(" List = {0}", listValues[listIndex]); } else if (get_rc == Rhino.Input.GetResult.Option) { if (gp.OptionIndex() == opList) { listIndex = gp.Option().CurrentListOptionIndex; } continue; } break; } return(Rhino.Commands.Result.Success); }
public Rhino.Commands.Result delete(Rhino.RhinoDoc doc) { // Input incomplate double _incomplate = 0.1; var input = new Rhino.Input.Custom.GetNumber(); input.SetCommandPrompt("Input incomplate(0.0 ~ 1.0)<0.1>"); Rhino.Input.GetResult res = input.Get(); if (res == Rhino.Input.GetResult.Number) { _incomplate = input.Number(); } if (_incomplate == 0.0) { _incomplate = 0.1; } // Select surface var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select elements"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Point; res = go.GetMultiple(1, 1024 * 10); if (res == Rhino.Input.GetResult.Nothing) { return(Rhino.Commands.Result.Failure); } System.Collections.Generic.List <Guid> list = new System.Collections.Generic.List <Guid>(); for (int i = 0; i < go.ObjectCount; i++) { Guid guid = go.Object(i).ObjectId; list.Add(guid); } int deleteCount = (int)((double)(list.Count) * _incomplate); Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects; for (int i = 0; i < deleteCount; i++) { Guid guid = list[i]; ot.Delete(guid, true); } return(Rhino.Commands.Result.Success); }
private void GetNestingSettings() { //Parameters Rhino.Input.Custom.GetOption gp = new Rhino.Input.Custom.GetOption(); gp.SetCommandPrompt("OpenNest: Set nesting settings"); Rhino.Input.Custom.OptionInteger Iterations = new Rhino.Input.Custom.OptionInteger(1, 1, 100); Rhino.Input.Custom.OptionDouble Spacing = new Rhino.Input.Custom.OptionDouble(0.01, 0.001, 10); Rhino.Input.Custom.OptionInteger Placement = new Rhino.Input.Custom.OptionInteger(1, 0, 4); Rhino.Input.Custom.OptionDouble Tolerance = new Rhino.Input.Custom.OptionDouble(0.1, 0.01, 10); Rhino.Input.Custom.OptionInteger Rotations = new Rhino.Input.Custom.OptionInteger(4, 0, 360); Rhino.Input.Custom.OptionInteger Seed = new Rhino.Input.Custom.OptionInteger(0, 1, 100); Rhino.Input.Custom.OptionDouble ClosestObjects = new Rhino.Input.Custom.OptionDouble(0.01, 0, 100); gp.AddOptionInteger("Iterations", ref Iterations); gp.AddOptionDouble("Spacing", ref Spacing); gp.AddOptionInteger("Placement", ref Placement); gp.AddOptionDouble("Tolerance", ref Tolerance); gp.AddOptionInteger("Rotations", ref Rotations); gp.AddOptionInteger("Seed", ref Seed); gp.AddOptionDouble("ClosestObjects", ref ClosestObjects); while (true) { Rhino.Input.GetResult get_rc = gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { break; } } this.iterations = Iterations.CurrentValue; this.spacing = Spacing.CurrentValue; this.placementType = Placement.CurrentValue; this.tolerance = Tolerance.CurrentValue; this.rotations = Rotations.CurrentValue; this.seed = Seed.CurrentValue; this.spacing *= (1 / tolerance); this.cp = ClosestObjects.CurrentValue; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Pick some objects to smooth Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to smooth"); go.SubObjectSelect = false; go.ReferenceObjectSelect = false; go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Mesh; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } // Prompt for some command line options. In this case, // we will clone the -Smooth command. Rhino.Input.Custom.GetOption gs = new Rhino.Input.Custom.GetOption(); gs.SetCommandPrompt("Choose smooth option"); gs.AcceptNothing(true); for (; ;) { gs.ClearCommandOptions(); Rhino.Input.Custom.OptionDouble smooth_factor_option = new Rhino.Input.Custom.OptionDouble(m_smooth_factor); Rhino.Input.Custom.OptionToggle use_cplane_option = new Rhino.Input.Custom.OptionToggle(m_use_cplane, "World", "CPlane"); Rhino.Input.Custom.OptionToggle smooth_x_option = new Rhino.Input.Custom.OptionToggle(m_smooth_x, "No", "Yes"); Rhino.Input.Custom.OptionToggle smooth_y_option = new Rhino.Input.Custom.OptionToggle(m_smooth_y, "No", "Yes"); Rhino.Input.Custom.OptionToggle smooth_z_option = new Rhino.Input.Custom.OptionToggle(m_smooth_z, "No", "Yes"); Rhino.Input.Custom.OptionToggle fix_boundaries_option = new Rhino.Input.Custom.OptionToggle(m_fix_boundaries, "No", "Yes"); int smooth_factor_index = gs.AddOptionDouble("SmoothFactor", ref smooth_factor_option); int use_cplane_index = gs.AddOptionToggle("CoordinateSystem", ref use_cplane_option); int smooth_x_index = gs.AddOptionToggle("X", ref smooth_x_option); int smooth_y_index = gs.AddOptionToggle("Y", ref smooth_y_option); int smooth_z_index = gs.AddOptionToggle("Z", ref smooth_z_option); int fix_boundaries_index = gs.AddOptionToggle("FixBoundaries", ref fix_boundaries_option); Rhino.Input.GetResult getrc = gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } if (getrc == Rhino.Input.GetResult.Option) { int index = gs.OptionIndex(); if (index == smooth_factor_index) { m_smooth_factor = smooth_factor_option.CurrentValue; } else if (index == use_cplane_index) { m_use_cplane = use_cplane_option.CurrentValue; } else if (index == smooth_x_index) { m_smooth_x = smooth_x_option.CurrentValue; } else if (index == smooth_y_index) { m_smooth_y = smooth_y_option.CurrentValue; } else if (index == smooth_z_index) { m_smooth_z = smooth_z_option.CurrentValue; } else if (index == fix_boundaries_index) { m_fix_boundaries = fix_boundaries_option.CurrentValue; } continue; } break; } // Build a command line macro that we can script StringBuilder sb = new StringBuilder(); sb.Append("_-Smooth "); sb.Append(string.Format("_SmoothFactor={0} ", m_smooth_factor)); sb.Append(string.Format("_CoordinateSystem={0} ", m_use_cplane ? "_CPlane" : "_World")); sb.Append(string.Format("_X={0} ", m_smooth_x ? "_Yes" : "_No")); sb.Append(string.Format("_Y={0} ", m_smooth_y ? "_Yes" : "_No")); sb.Append(string.Format("_Z={0} ", m_smooth_z ? "_Yes" : "_No")); sb.Append(string.Format("_FixBoundaries={0} ", m_fix_boundaries ? "_Yes" : "_No")); sb.Append("_Enter"); string script = sb.ToString(); #if (!RELEASE) Rhino.RhinoApp.WriteLine(script); #endif // Script the smooth command Rhino.RhinoApp.RunScript(script, false); return(Result.Success); }
/// <summary> /// Executes the platonic command /// </summary> protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode) { // Get the platonic geometry Rhino.Geometry.Brep[] faces = Platonic.Faces(); if (null == faces) { return(Rhino.Commands.Result.Failure); } // Prompt for center point string prompt = string.Format("Center of {0}", Platonic.DisplayName.ToLower()); Rhino.Geometry.Point3d origin; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetPoint(prompt, false, out origin); if (rc != Rhino.Commands.Result.Success) { return(rc); } double length = m_length; bool create_solid = m_create_solid; bool group_faces = m_group_faces; // Prompt for edge length PlatonicGetPoint get = new PlatonicGetPoint(faces, origin); get.SetCommandPrompt(Platonic.Prompt); get.SetDefaultNumber(length); get.SetBasePoint(origin, true); get.DrawLineFromPoint(origin, true); get.AcceptNumber(true, false); Rhino.Geometry.Transform xform = new Rhino.Geometry.Transform(1.0); rc = Rhino.Commands.Result.Cancel; for (; ;) { get.ClearCommandOptions(); Rhino.Input.Custom.OptionToggle output_toggle = null; Rhino.Input.Custom.OptionToggle group_toggle = null; output_toggle = new Rhino.Input.Custom.OptionToggle(create_solid, "Faces", "Solid"); get.AddOptionToggle("Output", ref output_toggle); if (!create_solid) { group_toggle = new Rhino.Input.Custom.OptionToggle(group_faces, "No", "Yes"); get.AddOptionToggle("Group", ref group_toggle); } Rhino.Input.GetResult res = get.Get(); if (res == Rhino.Input.GetResult.Point) { if (get.CalculateTransform(get.View().ActiveViewport, get.Point(), ref xform)) { m_length = get.Length; rc = Rhino.Commands.Result.Success; break; } } else if (res == Rhino.Input.GetResult.Number) { length = System.Math.Abs(get.Number()); if (get.CalculateTransform(get.View().ActiveViewport, length, ref xform)) { m_length = get.Length; rc = Rhino.Commands.Result.Success; break; } } else if (res == Rhino.Input.GetResult.Option) { if (null != output_toggle && create_solid != output_toggle.CurrentValue) { create_solid = output_toggle.CurrentValue; } if (null != group_toggle && group_faces != group_toggle.CurrentValue) { group_faces = group_toggle.CurrentValue; } continue; } else { break; } } // If we got here, then we have the center point and edge length, // any any command options. Time to add the geomtry to the document. if (rc == Rhino.Commands.Result.Success && xform.IsValid) { m_create_solid = create_solid; m_group_faces = group_faces; Rhino.DocObjects.ObjectAttributes attribs = doc.CreateDefaultAttributes(); attribs.Name = Platonic.Name; attribs.WireDensity = 0; // solid looks "nicer" with wires turned off... if (m_create_solid) { Rhino.Geometry.Brep[] breps = Rhino.Geometry.Brep.JoinBreps(faces, 2.1 * doc.ModelAbsoluteTolerance); foreach (Brep t in breps) { if (null == t) { continue; } t.Transform(xform); doc.Objects.AddBrep(t, attribs, null, false, false); } } else { if (m_group_faces) { attribs.AddToGroup(doc.Groups.Add()); } foreach (Brep t in faces) { if (null == t) { continue; } t.Transform(xform); doc.Objects.AddBrep(t, attribs, null, false, false); } } doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Pick all the points that you want to change to reinforcement."); go.GeometryFilter = geometryFilter; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (;;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); /* * if (res == Rhino.Input.GetResult.Option) * { * go.EnablePreSelect(false, true); * continue; * } * else if (res != Rhino.Input.GetResult.Option) * { * return Rhino.Commands.Result.Cancel; * } */ if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } List <Point3d> points = new List <Point3d>(); if (bHavePreselectedObjects) { for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int layerIndex = getLayerIndex(doc, "Reinforcement"); doc.Layers[layerIndex].Color = Color.Black; if (layerIndex == 999) { return(Result.Failure); } ObjRef[] objects = go.Objects(); foreach (ObjRef obj in objects) { Point3d point = obj.Point().Location; //TODO add the functionality how to assign different steel materials. Reinforcement reinf = new Reinforcement(ProjectPlugIn.Instance.CurrentBeam) { Material = new SteelMaterial("B500B", SteelType.Reinforcement, ProjectPlugIn.Instance.CurrentBeam), Centroid = point, Diameter = 8 }; ObjectAttributes attr = new ObjectAttributes(); attr.UserData.Add(reinf); attr.SetUserString("Name", "Reinforcement"); attr.LayerIndex = layerIndex; //Unused code to create a hatch around the point /* * doc.Objects.AddCurve(reinf.OutLine,attr); * ObjectAttributes attrHatch = new ObjectAttributes(); * attrHatch.LayerIndex = layerIndex; * doc.Objects.AddHatch(reinf.Hatch, attrHatch); */ doc.Objects.ModifyAttributes(obj, attr, true); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; int integer1 = 300; int integer2 = 300; Rhino.Input.Custom.OptionInteger optionInteger1 = new Rhino.Input.Custom.OptionInteger(integer1, 200, 900); Rhino.Input.Custom.OptionInteger optionInteger2 = new Rhino.Input.Custom.OptionInteger(integer2, 200, 900); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GeometryFilter = geometryFilter; go.AddOptionInteger("Option1", ref optionInteger1); go.AddOptionInteger("Option2", ref optionInteger2); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (; ;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); if (res == Rhino.Input.GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != Rhino.Input.GetResult.Object) { return(Rhino.Commands.Result.Cancel); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); 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++) { Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int objectCount = go.ObjectCount; integer1 = optionInteger1.CurrentValue; integer2 = optionInteger2.CurrentValue; Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount); Rhino.RhinoApp.WriteLine("Value of integer1 = {0}", integer1); Rhino.RhinoApp.WriteLine("Value of integer2 = {0}", integer2); return(Rhino.Commands.Result.Success); }
public Rhino.Commands.Result AddPoints(Rhino.RhinoDoc doc) { // Input interval double _interval = 0.1; double _noise = 1; // 1% noise var input = new Rhino.Input.Custom.GetNumber(); input.SetCommandPrompt("Input interval(0.0 ~ 1.0)<0.1>"); Rhino.Input.GetResult res = input.Get(); if (res == Rhino.Input.GetResult.Number) { _interval = input.Number(); } if (_interval == 0.0) { _interval = 0.1; } input.SetCommandPrompt("Noise factor(0.0 ~ 100.0)"); res = input.Get(); if (res == Rhino.Input.GetResult.Number) { _noise = input.Number(); } // Select surface var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select surface"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; res = go.GetMultiple(1, 1024); if (res == Rhino.Input.GetResult.Nothing) { return(Rhino.Commands.Result.Failure); } Utility.SetOutputCount(10); for (int i = 0; i < go.ObjectCount; i++) { Rhino.Geometry.Surface surfaceA = go.Object(i).Surface(); if (surfaceA == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Interval domU = surfaceA.Domain(0); Rhino.Geometry.Interval domV = surfaceA.Domain(1); double u, v; u = v = 0.0; for (u = domU.Min; u <= domU.Max; u += _interval) { for (v = domV.Min; v <= domV.Max; v += _interval) { Rhino.Geometry.Point3d pt = surfaceA.PointAt(u, v); Rhino.Geometry.Vector3d n = surfaceA.NormalAt(u, v); Rhino.Geometry.Point3d pt2 = randomPoint(surfaceA, u, v, _interval, _noise); doc.Objects.AddPoint(pt2); } } } return(Rhino.Commands.Result.Success); }
private Tuple <Brep[], Dictionary <int, List <Guid> > > GetObjectsToNest() { //Select Objects To Nest const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Annotation | Rhino.DocObjects.ObjectType.TextDot | Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("OpenNest: Select objects for nesting"); go.GeometryFilter = geometryFilter; go.GroupSelect = false; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(true); go.EnableUnselectObjectsOnExit(true); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (; ;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); if (res == Rhino.Input.GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != Rhino.Input.GetResult.Object) { return(null);//Rhino.Commands.Result.Cancel; } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } if (bHavePreselectedObjects) { // Normally when command finishes, pre-selected objects will remain // selected, when and post-selected objects will be unselected. // With this sample, it is possible to have a combination of // pre-selected and post-selected objects. To make sure everything // "looks the same", unselect everything before finishing the command. for (int i = 0; i < go.ObjectCount; i++) { Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } //doc.Views.Redraw(); } List <Guid> guids = new List <Guid>(); for (int i = 0; i < go.ObjectCount; i++) { guids.Add(go.Object(i).ObjectId); } Tuple <Brep[], Dictionary <int, List <Guid> > > data = OpenNestLib.OpenNestUtil.SortGuidsByPlanarCurves(guids, this.cp); Rhino.RhinoApp.WriteLine("OpenNest: Select object count = {0}", go.ObjectCount); this.n = data.Item1.Length; Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); return(data); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { List <Rhino.Geometry.Mesh> meshes = new List <Rhino.Geometry.Mesh>(); try { string ogre_bin = System.Environment.GetEnvironmentVariable("OGRE_HOME"); #if DEBUG ogre_bin += @"\bin\Debug"; #else ogre_bin += @"\bin\Release"; #endif string path = System.Environment.GetEnvironmentVariable("PATH"); System.Environment.SetEnvironmentVariable("PATH", path + ";" + ogre_bin, EnvironmentVariableTarget.Process); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); OptionToggle export_as_xml = new OptionToggle(false, "No", "Yes"); go.AddOptionToggle("export_as_xml", ref export_as_xml); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GeometryFilter = geometryFilter; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (; ;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); if (res == Rhino.Input.GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != Rhino.Input.GetResult.Object) { RhinoLogger.Info("Canceled."); return(Rhino.Commands.Result.Cancel); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } SaveFileDialog sv = new SaveFileDialog(); if (!export_as_xml.CurrentValue) { sv.Filter = "Mesh files (*.mesh)|*.mesh"; sv.DefaultExt = "mesh"; } else { sv.Filter = "XML files (*.xml)|*.xml"; sv.DefaultExt = "xml"; } sv.Title = "Select File to Export :"; if (sv.ShowDialog() != System.Windows.Forms.DialogResult.OK) { RhinoLogger.Info("Canceled."); return(Result.Cancel); } if (bHavePreselectedObjects) { // Normally when command finishes, pre-selected objects will remain // selected, when and post-selected objects will be unselected. // With this sample, it is possible to have a combination of // pre-selected and post-selected objects. To make sure everything // "looks the same", unselect everything before finishing the command. for (int i = 0; i < go.ObjectCount; i++) { Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int objectCount = go.ObjectCount; Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount); for (int i = 0; i < objectCount; i++) { var objref = go.Object(i); if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Mesh) { meshes.Add(objref.Mesh()); } else if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Brep) { var ms = CheckOrCreateMesh(objref.Brep(), RhinoDoc.ActiveDoc.GetMeshingParameters(MeshingParameterStyle.Custom)); meshes.AddRange(ms); } else { RhinoLogger.ErrorFormat("selection is unexpected ObjectType : {0}", objref.Geometry().ObjectType); return(Result.Failure); } } var exporter = new ExportToOgreMesh(); var exp_path = exporter.Export(sv.FileName, meshes); if (!export_as_xml.CurrentValue) { exporter.ConvertXmlToMesh(exp_path); } } catch (Exception e) { RhinoLogger.Fatal(e); return(Result.Failure); } return(Result.Success); }