public static Rhino.Commands.Result SpriteDrawing(RhinoDoc doc) { var sprite_mode = new Rhino.Input.Custom.OptionToggle(m_draw_single_sprite, "SpriteList", "SingleSprite"); var size_option = new Rhino.Input.Custom.OptionDouble(m_sprite_size); var space_option = new Rhino.Input.Custom.OptionToggle(m_draw_world_location, "Screen", "World"); var go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Sprite drawing mode"); go.AddOptionToggle("Mode", ref sprite_mode); go.AddOptionDouble("Size", ref size_option); go.AddOptionToggle("DrawSpace", ref space_option); int option_go = go.AddOption("Spin"); int option_file = go.AddOption("FileSprite"); Rhino.Display.DisplayPipeline.PostDrawObjects += DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox; doc.Views.Redraw(); while (go.Get() == Rhino.Input.GetResult.Option) { m_draw_single_sprite = sprite_mode.CurrentValue; m_sprite_size = (float)size_option.CurrentValue; m_draw_world_location = space_option.CurrentValue; if (go.OptionIndex() == option_go) { var gs = new Rhino.Input.Custom.GetOption(); gs.SetCommandPrompt("press enter/escape to end"); gs.SetWaitDuration(1); var vp = doc.Views.ActiveView.MainViewport; while (gs.Get() == Rhino.Input.GetResult.Timeout) { vp.Rotate(0.1, Vector3d.ZAxis, Point3d.Origin); doc.Views.Redraw(); } } else if (go.OptionIndex() == option_file) { var dlg = new Rhino.UI.OpenFileDialog(); if (dlg.ShowDialog()) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(dlg.FileName); m_sprite = new Rhino.Display.DisplayBitmap(bmp); } doc.Views.Redraw(); } else { doc.Views.Redraw(); } } Rhino.Display.DisplayPipeline.PostDrawObjects -= DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox -= DisplayPipeline_CalculateBoundingBox; return(Rhino.Commands.Result.Success); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { var sprite_mode = new Rhino.Input.Custom.OptionToggle(m_draw_single_sprite, "SpriteList", "SingleSprite"); var size_option = new Rhino.Input.Custom.OptionDouble(m_sprite_size); var space_option = new Rhino.Input.Custom.OptionToggle(m_draw_world_location, "Screen", "World"); var go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Sprite drawing mode"); go.AddOptionToggle("Mode", ref sprite_mode); go.AddOptionDouble("Size", ref size_option); go.AddOptionToggle("DrawSpace", ref space_option); int option_go = go.AddOption("Spin"); int option_file = go.AddOption("FileSprite"); Rhino.Display.DisplayPipeline.PostDrawObjects += DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox; doc.Views.Redraw(); while (go.Get() == Rhino.Input.GetResult.Option) { m_draw_single_sprite = sprite_mode.CurrentValue; m_sprite_size = (float)size_option.CurrentValue; m_draw_world_location = space_option.CurrentValue; if (go.OptionIndex() == option_go) { var gs = new Rhino.Input.Custom.GetOption(); gs.SetCommandPrompt("press enter/escape to end"); gs.SetWaitDuration(1); var vp = doc.Views.ActiveView.MainViewport; while (gs.Get() == Rhino.Input.GetResult.Timeout) { vp.Rotate(0.1, Vector3d.ZAxis, Point3d.Origin); doc.Views.Redraw(); } } else if (go.OptionIndex() == option_file) { System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog(); if (dlg.ShowDialog(RhinoApp.MainWindow()) == System.Windows.Forms.DialogResult.OK) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(dlg.FileName); m_sprite = new Rhino.Display.DisplayBitmap(bmp); } doc.Views.Redraw(); } else doc.Views.Redraw(); } Rhino.Display.DisplayPipeline.PostDrawObjects -= DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox -= DisplayPipeline_CalculateBoundingBox; 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 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; }
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); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { Rhino.DocObjects.ObjRef objref; var rc = Rhino.Input.RhinoGet.GetOneObject("Select object", true, Rhino.DocObjects.ObjectType.AnyObject, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } rc = Rhino.Input.RhinoGet.GetPoint("Start point", false, out m_point_start); if (rc != Rhino.Commands.Result.Success) { return(rc); } var obj = objref.Object(); if (obj == null) { return(Rhino.Commands.Result.Failure); } // create an instance of a GetPoint class and add a delegate // for the DynamicDraw event var gp = new Rhino.Input.Custom.GetPoint(); gp.DrawLineFromPoint(m_point_start, true); var optdouble = new Rhino.Input.Custom.OptionDouble(m_distance); bool constrain = false; var optconstrain = new Rhino.Input.Custom.OptionToggle(constrain, "Off", "On"); gp.AddOptionDouble("Distance", ref optdouble); gp.AddOptionToggle("Constrain", ref optconstrain); gp.DynamicDraw += ArrayByDistanceDraw; gp.Tag = obj; while (gp.Get() == Rhino.Input.GetResult.Option) { m_distance = optdouble.CurrentValue; if (constrain != optconstrain.CurrentValue) { constrain = optconstrain.CurrentValue; if (constrain) { var gp2 = new Rhino.Input.Custom.GetPoint(); gp2.DrawLineFromPoint(m_point_start, true); gp2.SetCommandPrompt("Second point on constraint line"); if (gp2.Get() == Rhino.Input.GetResult.Point) { gp.Constrain(m_point_start, gp2.Point()); } else { gp.ClearCommandOptions(); optconstrain.CurrentValue = false; constrain = false; gp.AddOptionDouble("Distance", ref optdouble); gp.AddOptionToggle("Constrain", ref optconstrain); } } else { gp.ClearConstraints(); } } } if (gp.CommandResult() == Rhino.Commands.Result.Success) { m_distance = optdouble.CurrentValue; var pt = gp.Point(); var vec = pt - m_point_start; double length = vec.Length; vec.Unitize(); int count = (int)(length / m_distance); for (int i = 1; i < count; i++) { var translate = vec * (i * m_distance); var xf = Rhino.Geometry.Transform.Translation(translate); doc.Objects.Transform(obj, xf, false); } doc.Views.Redraw(); } return(gp.CommandResult()); }
/// <summary> /// Called when the command is in scripted mode /// </summary> /// <param name="model"></param> /// <returns></returns> static Result RunScript(TextViewModel model) { var height = new Rhino.Input.Custom.OptionDouble(model.textHeight); var bold = new Rhino.Input.Custom.OptionToggle(model.bold, Localization.LocalizeCommandOptionValue("No", 396), Localization.LocalizeCommandOptionValue("Yes", 397)); var italic = new Rhino.Input.Custom.OptionToggle(model.italic, Localization.LocalizeCommandOptionValue("No", 398), Localization.LocalizeCommandOptionValue("Yes", 399)); var mask = new Rhino.Input.Custom.OptionToggle(model.maskEnabled, Localization.LocalizeCommandOptionValue("No", 400), Localization.LocalizeCommandOptionValue("Yes", 401)); var masksource = new Rhino.Input.Custom.OptionToggle(model.maskUsesViewportColor, Localization.LocalizeCommandOptionValue("No", 402), Localization.LocalizeCommandOptionValue("Yes", 403)); var maskcolor = new Rhino.Input.Custom.OptionColor(model.maskColor); var maskborder = new Rhino.Input.Custom.OptionDouble(model.maskOffset, true, 0); string facename = model.Font.FaceName; string newtext = ""; var go = new Rhino.Input.Custom.GetString(); var get_rc = Rhino.Input.GetResult.Cancel; var rc = Rhino.Commands.Result.Cancel; while (get_rc != Rhino.Input.GetResult.Nothing && get_rc != Rhino.Input.GetResult.String) { go.ClearCommandOptions(); go.AcceptNothing(true); go.SetCommandPrompt(LOC.STR("Text string")); int faceopt = go.AddOption(LOC.CON("Font")); go.AddOptionDouble(LOC.CON("Height"), ref height, LOC.STR("Text height")); go.AddOptionToggle(LOC.CON("Italic"), ref italic); go.AddOptionToggle(LOC.CON("Mask"), ref mask); go.AddOptionToggle(LOC.CON("UseBackgroundColor"), ref masksource); go.AddOptionColor(LOC.CON("MaskColor"), ref maskcolor); go.AddOptionDouble(LOC.CON("MaskMargin"), ref maskborder); get_rc = go.Get(); switch (get_rc) { case Rhino.Input.GetResult.Cancel: return Rhino.Commands.Result.Cancel; case Rhino.Input.GetResult.String: newtext = go.StringResult(); break; case Rhino.Input.GetResult.Option: if( go.OptionIndex() == faceopt ) { string oldname = facename; rc = Rhino.Input.RhinoGet.GetString(LOC.STR("Font name"), true, ref facename); if( rc!=Rhino.Commands.Result.Success) return rc; if (string.IsNullOrWhiteSpace(facename)) facename = oldname; } break; } } if (string.IsNullOrWhiteSpace(newtext)) return Rhino.Commands.Result.Cancel; // update default settings model.text = newtext; int fontindex = model.Doc.Fonts.FindOrCreate(facename, bold.CurrentValue, italic.CurrentValue); model.fontIndex = fontindex; model.textHeight = height.CurrentValue; model.maskEnabled = mask.CurrentValue; model.maskUsesViewportColor = masksource.CurrentValue; model.maskColor = maskcolor.CurrentValue; model.maskOffset = maskborder.CurrentValue; return Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string selectedLayer; Color selectedColour; // For this example we will use a GetPoint class, but all of the custom // "Get" classes support command line options. Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select panels to create borders"); double border = Properties.Settings.Default.PanelBorderDefault; // Default borderSize is 50 // set up the options Rhino.Input.Custom.OptionDouble borderSizeOption = new Rhino.Input.Custom.OptionDouble(border); go.AddOptionDouble("Borders", ref borderSizeOption); go.AcceptNumber(true, true); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.EnableSelPrevious(true); go.EnablePreSelect(true, false); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; RequiredLayer getRequiredLayer = new RequiredLayer(); getRequiredLayer.ShowDialog(); selectedLayer = getRequiredLayer.getLayerName(); selectedColour = getRequiredLayer.getSelectedColor(); while (true) { go.ClearCommandOptions(); borderSizeOption = new Rhino.Input.Custom.OptionDouble(border); go.AddOptionDouble("Borders", ref borderSizeOption); // perform the get operation. This will prompt the user to select the list of curves, but also // allow for command line options defined above GetResult result = go.GetMultiple(1, 0); if (result == GetResult.Option) { border = borderSizeOption.CurrentValue; go.EnablePreSelect(false, true); continue; } else if (result == GetResult.Number) { border = go.Number(); continue; } else if (result != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); continue; } break; } int objecTCount = go.ObjectCount; border = borderSizeOption.CurrentValue; foreach (ObjRef objRef in go.Objects()) { Curve curve = objRef.Curve(); // If curve is null, means objRef is not a curve if (curve == null) { continue; } // If curve is not Closed Curve if (curve.IsClosed == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is open"); continue; } if (curve.IsPlanar() == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is not planar"); continue; } // Process the curve Plane plane = Rhino.Geometry.Plane.WorldXY; Curve[] offsetCurves; int layerIndex = doc.Layers.CurrentLayerIndex; RhinoUtilities.SetActiveLayer(selectedLayer, selectedColour); //if (curve.TryGetPlane(out plane)) //{ if (border < 0) //If the border is negative, it means the border should be drawn outside the perimeter { plane.XAxis = -plane.XAxis; plane.YAxis = -plane.YAxis; plane.ZAxis = -plane.ZAxis; offsetCurves = curve.Offset(plane, border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); } else { offsetCurves = curve.Offset(plane, -border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); } //Check if the curve is outside border and border is a positive if (curve.Contains(offsetCurves[0].PointAtStart, Plane.WorldXY, 0) == PointContainment.Outside && border > 0) { offsetCurves = curve.Offset(plane, border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); //if true, then try to set the curve to be within the border } //Check if the curve is within the border and border is a negative if (curve.Contains(offsetCurves[0].PointAtStart, Plane.WorldXY, 0) == PointContainment.Inside && border < 0) { offsetCurves = curve.Offset(plane, -border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); //if true, then try to set the curve to be outside the border } foreach (Curve c in offsetCurves) { doc.Objects.AddCurve(c); } doc.Layers.SetCurrentLayerIndex(layerIndex, true); } doc.Views.Redraw(); Properties.Settings.Default.PanelBorderDefault = border; Properties.Settings.Default.Save(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // For this example we will use a GetPoint class, but all of the custom // "Get" classes support command line options. Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select panels to create fixing holes"); //get the default values for the properties double holeSize = Properties.Settings.Default.FixingHoleSize; double offsetX = Properties.Settings.Default.FixingHoleOffsetX; double offsetY = Properties.Settings.Default.FixingHoleOffsetY; double spacing = Properties.Settings.Default.FixingHoleSpacing; double minSpacing = Properties.Settings.Default.FixingHoleMinimum; // set up the options Rhino.Input.Custom.OptionDouble holeSizeOption = new Rhino.Input.Custom.OptionDouble(holeSize); Rhino.Input.Custom.OptionDouble offsetXOption = new Rhino.Input.Custom.OptionDouble(offsetX); Rhino.Input.Custom.OptionDouble offsetYOption = new Rhino.Input.Custom.OptionDouble(offsetY); Rhino.Input.Custom.OptionDouble spacingOption = new Rhino.Input.Custom.OptionDouble(spacing); Rhino.Input.Custom.OptionDouble minSpacingOption = new Rhino.Input.Custom.OptionDouble(minSpacing); //using option to get values and save automatically(only if user enters) go.AddOptionDouble("HoleSize", ref holeSizeOption); go.AddOptionDouble("OffsetX", ref offsetXOption); go.AddOptionDouble("OffsetY", ref offsetYOption); go.AddOptionDouble("Spacing", ref spacingOption); go.AddOptionDouble("MinSpacing", ref minSpacingOption); go.AcceptNumber(true, true); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.EnableSelPrevious(true); go.EnablePreSelect(true, false); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; while (true) { go.ClearCommandOptions(); holeSizeOption = new Rhino.Input.Custom.OptionDouble(holeSize); offsetXOption = new Rhino.Input.Custom.OptionDouble(offsetX); offsetYOption = new Rhino.Input.Custom.OptionDouble(offsetY); spacingOption = new Rhino.Input.Custom.OptionDouble(spacing); minSpacingOption = new Rhino.Input.Custom.OptionDouble(minSpacing); go.AddOptionDouble("HoleSize", ref holeSizeOption); go.AddOptionDouble("OffsetX", ref offsetXOption); go.AddOptionDouble("OffsetY", ref offsetYOption); go.AddOptionDouble("Spacing", ref spacingOption); go.AddOptionDouble("MinSpacing", ref minSpacingOption); // perform the get operation. This will prompt the user to select the list of curves, but also // allow for command line options defined above GetResult result = go.GetMultiple(1, 0); if (result == GetResult.Option) { holeSize = holeSizeOption.CurrentValue; offsetX = offsetXOption.CurrentValue; offsetY = offsetYOption.CurrentValue; spacing = spacingOption.CurrentValue; minSpacing = minSpacingOption.CurrentValue; go.EnablePreSelect(false, true); continue; } //else if (result == GetResult.Number) //{ // border = go.Number(); // continue; //} else if (result != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); continue; } break; } int objecTCount = go.ObjectCount; foreach (ObjRef objRef in go.Objects()) { Curve curve = objRef.Curve(); // If curve is null, means objRef is not a curve if (curve == null) { continue; } // If curve is not Closed Curve if (curve.IsClosed == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is open"); continue; } if (curve.IsPlanar() == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is not planar"); continue; } // Find the boundary BoundingBox boundingBox = curve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; List <Point3d> pointsList = new List <Point3d> (); // Calculate top and bottom fixing holes double runningX = min.X + offsetX; //25 double runningY = max.Y - offsetY; //-626.5 Point3d point; while (runningX < (max.X - offsetX) - minSpacing) { point = new Point3d(runningX, runningY, 0); pointsList.Add(point); point = new Point3d(runningX, min.Y + offsetY, 0); pointsList.Add(point); runningX = runningX + spacing; } point = new Point3d(max.X - offsetX, runningY, 0); //adds the top right fixing hole pointsList.Add(point); point = new Point3d(max.X - offsetX, min.Y + offsetY, 0); //adds the bottom right fixing hole pointsList.Add(point); runningY = runningY - spacing; // Calculate the sides while (runningY > (min.Y - offsetY) + minSpacing) { point = new Point3d(min.X + offsetX, runningY, 0); //adds the left fixing holes pointsList.Add(point); point = new Point3d(max.X - offsetX, runningY, 0); //adds the right fixing hole pointsList.Add(point); runningY = runningY - spacing; } // Process the curve Plane plane = Rhino.Geometry.Plane.WorldXY; int layerIndex = doc.Layers.CurrentLayerIndex; RhinoUtilities.SetActiveLayer("Fixing Holes", System.Drawing.Color.Black); // Draw all the holes Round round = new Round(); round.X = holeSize; foreach (Point3d p in pointsList) { round.drawTool(p); } //Round round = new Round(); //round.X = holeSize; //round.drawTool(point); //offsetCurves = curve.Offset(plane, -border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); //if (curve.Contains(offsetCurves[0].PointAtStart, Plane.WorldXY, 0) == PointContainment.Outside) //{ // offsetCurves = curve.Offset(plane, border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); //} //foreach (Curve c in offsetCurves) //{ // doc.Objects.AddCurve(c); //} //// } doc.Layers.SetCurrentLayerIndex(layerIndex, true); } doc.Views.Redraw(); Properties.Settings.Default.FixingHoleSize = holeSize; Properties.Settings.Default.FixingHoleOffsetX = offsetX; Properties.Settings.Default.FixingHoleOffsetY = offsetY; Properties.Settings.Default.FixingHoleSpacing = spacing; Properties.Settings.Default.FixingHoleMinimum = minSpacing; Properties.Settings.Default.Save(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Get a polyframe // Get a new point // Create the pipes and lines in the new location // the lines will be from an edge container of the PolyFrame // The pipes will be added extra. This will allow for the pipes to be used as a PolyFrame var primal = new PFoam(); var dual = new PFoam(); try { var guids = LoadData.LoadPrimalDual(out primal, out dual, out ContainerType container); if (primal.Cells.Count < 1) { Rhino.RhinoApp.WriteLine("Error loading PolyFrame from provided data!"); return(Result.Failure); } var form = primal.Edges.Where(e => e.Id > 0).Any(x => x.Faces.Count < 2); if (dual.Cells.Count < 1) { RhinoApp.WriteLine("Could not load dual from the selected PolyFrame."); return(Result.Failure); } double minLen; double maxLen; var pipePolyFrame = new PFoam(); if (form) { pipePolyFrame = primal; } else { pipePolyFrame = dual; } var edgeLengths = pipePolyFrame.Edges.Select(x => x.GetLength()); minLen = edgeLengths.Min(); maxLen = edgeLengths.Max(); //var medLen = edgeLengths.Average(); var gp = new Rhino.Input.Custom.GetPoint(); var minRadius = new Rhino.Input.Custom.OptionDouble(minLen / 10, true, double.Epsilon); var maxRadius = new Rhino.Input.Custom.OptionDouble(minLen / 2, true, double.Epsilon); gp.SetCommandPrompt("Place the Pipes. Hit <Enter> to replace Input"); gp.SetDefaultPoint(primal.Centroid); gp.AcceptPoint(true); gp.AddOptionDouble("MinRadius", ref minRadius); gp.AddOptionDouble("MaxRadius", ref maxRadius); while (true) { gp.Get(); if (gp.Result() == Rhino.Input.GetResult.Point) { break; } else if (gp.Result() == Rhino.Input.GetResult.Cancel) { return(Result.Failure); } } var moveVect = gp.Point() - pipePolyFrame.Centroid; pipePolyFrame.Offset(moveVect); if (gp.GotDefault()) { if (!form) { moveVect = primal.Centroid - dual.Centroid; } doc.Objects.Delete(guids, true); doc.Views.Redraw(); } var pipeLayer = new Rhino.DocObjects.Layer() { Name = "_Pipes" }; if (doc.Layers.All(x => x.Name != pipeLayer.Name)) { doc.Layers.Add(pipeLayer); } pipeLayer = doc.Layers.First(x => x.Name == "_Pipes"); var pipeCol = pipePolyFrame.PipeGeoDual(minRadius.CurrentValue, maxRadius.CurrentValue, pipePolyFrame.Edges.Select(x => x.Id).ToList()); var pipeGuids = new List <Guid>(); foreach (var pc in pipeCol) { var att = new Rhino.DocObjects.ObjectAttributes { LayerIndex = pipeLayer.Index, ObjectColor = pc.Item2, ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject }; pipeGuids.Add(doc.Objects.AddBrep(pc.Item1, att)); } doc.Groups.Add(pipePolyFrame.Id.ToString() + "_Pipes", pipeGuids); pipePolyFrame.SaveAsEdges(); doc.Views.Redraw(); } catch (PolyFrameworkException pfE) { RhinoApp.WriteLine(pfE.Message); primal.Hide(); dual.Hide(); return(Result.Failure); } return(Result.Success); }