protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetObject go = new GetObject(); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (; ;) { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } BoundingBox box = BoundingBox.Empty; for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { box.Union(rhinoObject.Geometry.GetBoundingBox(true)); } rhinoObject.Select(false); } if (box.IsValid) { RFContext.ClippingBox = new Box(box); //RFContext.Clip = true; return(Result.Success); } return(Result.Nothing); }
public static GetObject GetRhinoObjects(string prompt, ObjectType geometryFilter) { GetObject go = new GetObject(); go.SetCommandPrompt(prompt); go.GeometryFilter = geometryFilter; go.GroupSelect = false; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = true; for (; ;) { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != GetResult.Object) { return(go); } 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++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } } return(go); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: start here modifying the behaviour of your command. //Select objects try { GetObject go = new GetObject(); go.EnablePreSelect(true, true); go.EnablePostSelect(true); go.SetCommandPrompt("Super Intersection | Advanced Boolean Intersection:"); go.GetMultiple(1, 0); if (go.ObjectCount > 0) { RhinoApp.RunScript("_BooleanIntersection", true); RhinoApp.RunScript("_SelLast", true); RhinoApp.RunScript("_MergeAllFaces", true); RhinoApp.RunScript("_ShrinkTrimmedSrf", true); } return(Result.Success); } catch { return(Result.Failure); } }
/// <summary> /// This function selects breps /// </summary> /// /// public static bool XSelectBreps(string message, out RhinoList <Brep> breps) { breps = new RhinoList <Brep>(); int i; var gc = new GetObject(); gc.SetCommandPrompt("Select some Breps"); gc.EnablePreSelect(true, true); gc.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gc.GetMultiple(1, 0); //we do our double check to make sure the user selected something if (gc.CommandResult() != Result.Success) { return(false); } for (i = 0; i < gc.ObjectCount; i++) { var brep = gc.Object(i).Brep(); if (null != brep) { breps.Add(brep); } } return(true); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gm = new GetObject(); gm.SetCommandPrompt("Select mesh"); gm.GeometryFilter = ObjectType.Mesh; gm.Get(); if (gm.CommandResult() != Result.Success) { return(gm.CommandResult()); } var gp = new GetObject(); gp.SetCommandPrompt("Select polyline"); gp.GeometryFilter = ObjectType.Curve; gp.EnablePreSelect(false, true); gp.DeselectAllBeforePostSelect = false; gp.Get(); if (gm.CommandResult() != Result.Success) { return(gp.CommandResult()); } var mesh = gm.Object(0).Mesh(); if (null == mesh) { return(Result.Failure); } var curve = gp.Object(0).Curve(); if (null == curve) { return(Result.Failure); } var polyline_curve = curve as PolylineCurve; if (null == polyline_curve) { RhinoApp.Write("Curve is not a polyline"); return(Result.Nothing); } int[] face_ids; var points = Rhino.Geometry.Intersect.Intersection.MeshPolyline(mesh, polyline_curve, out face_ids); if (points.Length > 0) { foreach (var pt in points) { doc.Objects.AddPoint(pt); } doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go0 = new GetObject(); go0.SetCommandPrompt("Select surface or polysurface to subtract from"); go0.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter; go0.SubObjectSelect = false; go0.Get(); if (go0.CommandResult() != Result.Success) { return(go0.CommandResult()); } var brep0 = go0.Object(0).Brep(); if (null == brep0) { return(Result.Failure); } var go1 = new GetObject(); go1.SetCommandPrompt("Select surface or polysurface to subtract with"); go1.GeometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter; go1.SubObjectSelect = false; go1.EnablePreSelect(false, true); go1.DeselectAllBeforePostSelect = false; go1.Get(); if (go1.CommandResult() != Result.Success) { return(go1.CommandResult()); } var brep1 = go1.Object(0).Brep(); if (null == brep1) { return(Result.Failure); } var tolerance = doc.ModelAbsoluteTolerance; var out_breps = Brep.CreateBooleanDifference(brep0, brep1, tolerance); if (null != out_breps && out_breps.Length > 0) { foreach (var b in out_breps) { doc.Objects.AddBrep(b); } doc.Objects.Delete(go0.Object(0).ObjectId, true); doc.Objects.Delete(go1.Object(0).ObjectId, true); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var get_outer = new GetObject(); get_outer.SetCommandPrompt("Outer profile curve"); get_outer.GeometryFilter = ObjectType.Curve; get_outer.SubObjectSelect = false; get_outer.Get(); if (get_outer.CommandResult() != Result.Success) { return(get_outer.CommandResult()); } var outer = get_outer.Object(0).Curve(); if (null == outer) { return(Result.Failure); } var get_inner = new GetObject(); get_inner.SetCommandPrompt("Inner profile curve"); get_inner.GeometryFilter = ObjectType.Curve; get_inner.SubObjectSelect = false; get_inner.EnablePreSelect(false, true); get_inner.DeselectAllBeforePostSelect = false; get_inner.GetMultiple(1, 0); if (get_inner.CommandResult() != Result.Success) { return(get_outer.CommandResult()); } var inners = new Curve[get_inner.ObjectCount]; for (var i = 0; i < get_inner.ObjectCount; i++) { var inner = get_inner.Object(i).Curve(); if (null == inner) { return(Result.Failure); } inners[i] = inner; } var extrusion = CreateExtrusion(outer, inners, 10); if (null != extrusion) { doc.Objects.AddExtrusion(extrusion); doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType selFilter = ObjectType.PolysrfFilter | ObjectType.Extrusion; bool value = false; double preShrinkValue = ZERO_CM; OptionToggle shrinkToDimensions = new OptionToggle(value, "Off", "On"); OptionDouble preShrink = new OptionDouble(preShrinkValue, 0.0, 1.0); ObjRef boxObjRef = null; GetObject go = new GetObject(); go.SetCommandPrompt("Select the box to net-ify"); go.AddOptionToggle("Constrain", ref shrinkToDimensions); go.AddOptionDouble("PreShrink", ref preShrink, "Preshrink"); go.GeometryFilter = selFilter; go.EnableClearObjectsOnEntry(true); go.EnableUnselectObjectsOnExit(true); // TODO: clean up this hot mess for (;;) { GetResult getObjResult = go.Get(); if (getObjResult == GetResult.Object) { boxObjRef = go.Object(0); boxObjRef.Object().Select(on: true, syncHighlight: true); go.EnablePreSelect(false, true); go.AcceptNothing(true); continue; } else if (getObjResult == GetResult.Cancel) { return(Result.Cancel); } // Case where user presses enter else if (getObjResult == GetResult.Nothing) { if (boxObjRef != null) { preShrinkValue = preShrink.CurrentValue; if (preShrinkValue != ZERO_CM) { boxObjRef = shrinkBoxObj(boxObjRef, preShrinkValue); } drawNetFromObjRef(boxObjRef, doc, shrinkToDimensions.CurrentValue); return(Result.Success); } } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var go = new GetObject(); go.SetCommandPrompt("Select grips to move"); go.GeometryFilter = ObjectType.Grip; go.EnablePreSelect(true, true); go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var gp = new GetPoint(); gp.SetCommandPrompt("Point to move from"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var from = gp.Point(); gp.SetCommandPrompt("Point to move to"); gp.SetBasePoint(from, true); gp.DrawLineFromPoint(from, true); gp.Get(); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var to = gp.Point(); var dir = to - from; if (dir.IsTiny(doc.ModelAbsoluteTolerance)) { return(Result.Nothing); } var xform = Transform.Translation(dir); var helper = new SampleCsGripHelper(doc); helper.AddGripObjects(go); helper.TransformAndUpdate(xform); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Check the selected dot GetObject go = new GetObject(); 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.Annotation; go.SetCommandPrompt("Select Text to replace:"); GetResult result = go.GetMultiple(1, -1); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount); List <TextEntity> textEntityList = new List <TextEntity>(); List <RhinoObject> rhinoObjectList = new List <RhinoObject>(); // Loop through all the objects to find Text for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (rhinoObject.ObjectType == ObjectType.Annotation) { TextEntity textEntity = rhinoObject.Geometry as TextEntity; if (textEntity != null) { rhinoObjectList.Add(rhinoObject); } } } FindAndReplaceForm findForm = new FindAndReplaceForm(rhinoObjectList); findForm.ShowDialog(RhinoApp.MainWindow()); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Check the selected curve GetObject go = new GetObject(); 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; GetResult result = go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } if (go.ObjectCount != 1) { RhinoApp.WriteLine("Error: {0} curve is selected.", go.ObjectCount); return(Rhino.Commands.Result.Failure); } RhinoApp.WriteLine("{0} curve is selected.", go.ObjectCount); Curve curve = go.Object(0).Curve(); // If curve is null if (curve == null) { return(Rhino.Commands.Result.Failure); } // If curve is Closed Curve Orientation if (curve.IsClosed == false) { RhinoApp.WriteLine("The curve is open"); return(Rhino.Commands.Result.Failure); } RhinoUtilities.SetActiveLayer(Properties.Settings.Default.PerforationLayerName, System.Drawing.Color.Green); PerforationForm perforationForm = new PerforationForm(curve); perforationForm.ShowDialog(RhinoApp.MainWindow()); RhinoDoc.ActiveDoc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var have_preselected_objects = false; var go = new GetObject(); go.SetCommandPrompt("Select objects"); go.GeometryFilter = ObjectType.AnyObject; go.GroupSelect = true; go.SubObjectSelect = false; while (true) { go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } if (go.ObjectsWerePreselected) { have_preselected_objects = true; go.EnablePreSelect(false, true); go.AlreadySelectedObjectSelect = true; go.EnableClearObjectsOnEntry(false); go.DeselectAllBeforePostSelect = false; go.EnableUnselectObjectsOnExit(false); continue; } break; } if (have_preselected_objects) { for (var i = 0; i < go.ObjectCount; i++) { var obj = go.Object(i).Object(); obj?.Select(false); } doc.Views.Redraw(); } RhinoApp.WriteLine("Select object count: {0}", go.ObjectCount); return(Result.Success); }
private static List <RhinoObject> GetObjectSelection(ObjectType filter = ObjectType.AnyObject) { // Construct an objects getter var getObj = new GetObject(); getObj.SetCommandPrompt("Select geometry"); getObj.GroupSelect = true; getObj.SubObjectSelect = false; getObj.EnableClearObjectsOnEntry(false); getObj.EnableUnselectObjectsOnExit(false); getObj.DeselectAllBeforePostSelect = false; getObj.GeometryFilter = filter; // Get objects for (; ;) { GetResult res = getObj.GetMultiple(1, 0); if (res == GetResult.Option) { getObj.EnablePreSelect(false, true); continue; } else if (res != GetResult.Object) { return(null); } if (getObj.ObjectsWerePreselected) { getObj.EnablePreSelect(false, true); continue; } break; } return(getObj.Objects().Select(o => o.Object()).ToList()); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetObject getObjs = new GetObject(); getObjs.SetCommandPrompt("Select objects for schema removal"); getObjs.GroupSelect = true; getObjs.SubObjectSelect = false; getObjs.EnableClearObjectsOnEntry(false); getObjs.EnableUnselectObjectsOnExit(false); getObjs.DeselectAllBeforePostSelect = false; bool hasPreselected = false; for (; ;) { GetResult res = getObjs.GetMultiple(1, 0); if (res != GetResult.Object) { return(Result.Cancel); } if (getObjs.ObjectsWerePreselected) { hasPreselected = true; getObjs.EnablePreSelect(false, true); continue; } break; } //This chunk just makes sure objects selected during the command stay selected afterwards. Optional. if (hasPreselected) { SelectAllCommandObjs(getObjs, doc); } List <RhinoObject> objs = getObjs.Objects().Select(o => o.Object()).ToList(); foreach (RhinoObject obj in objs) { obj.Attributes.DeleteUserString(SpeckleSchemaKey); } return(Result.Success); }
//============================== private Curve[] GetCurves() { GetObject go = new GetObject(); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.SetCommandPrompt("Hyper Split | Split All Curves With One Another:"); go.EnablePreSelect(true, true); go.EnablePostSelect(true); go.GetMultiple(1, 0); Curve[] CurveSel = new Curve[go.ObjectCount]; TempRef = go.Objects(); for (int i = 0; i < go.ObjectCount; i++) { CurveSel[i] = go.Object(i).Curve(); } return(CurveSel); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { List <RhinoObject> objs = new List <RhinoObject>(); using (GetObject getter = new GetObject()) { getter.EnablePreSelect(true, false); getter.SetCommandPrompt("Select all the objects you want to tag"); getter.AcceptColor(false); getter.AcceptString(false); getter.GroupSelect = true; getter.GetMultiple(1, 0); if (getter.CommandResult() != Result.Success) { return(getter.CommandResult()); } for (int i = 0; i < getter.ObjectCount; i++) { objs.Add(getter.Object(i).Object()); } } string tagName; using (GetString getter = new GetString()) { getter.SetCommandPrompt("Enter the tag"); if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input for tag"); return(getter.CommandResult()); } tagName = getter.StringResult(); } TagUtil.AddTag(objs, tagName, true); doc.Modified = true; doc.Objects.UnselectAll(); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { // TODO: start here modifying the behaviour of your command. // --- RhinoApp.WriteLine("The {0} command will select the curve with same length", EnglishName); double tolerance = 0.001; Rhino.Commands.Result rc = Rhino.Commands.Result.Failure; using (GetObject getObjectAction = new GetObject()) { getObjectAction.GeometryFilter = ObjectType.Curve; getObjectAction.SetCommandPrompt("Please select curves"); var dblOption = new OptionDouble(tolerance, true, 0); getObjectAction.AddOptionDouble("SelectionTolerance", ref dblOption); getObjectAction.EnablePreSelect(true, true); var result = getObjectAction.Get(); double refLength = 0.0; if (result == GetResult.Object) { var value = getObjectAction.Object(0); var crv = value.Curve(); if (crv != null) { refLength = crv.GetLength(); var objects = doc.Objects.FindByObjectType(ObjectType.Curve); foreach (var obj in objects) { var _curve = (new ObjRef(obj)).Curve(); if (Rhino.RhinoMath.EpsilonEquals(_curve.GetLength(), refLength, dblOption.CurrentValue)) { obj.Select(true); } } rc = Rhino.Commands.Result.Success; } } } doc.Views.Redraw(); return(rc); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gs = new GetObject(); gs.SetCommandPrompt("Select surface"); gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gs.SubObjectSelect = true; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } var face = gs.Object(0).Face(); if (null == face) { return(Result.Failure); } var gc = new GetObject(); gc.SetCommandPrompt("Select curve"); gc.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gc.EnablePreSelect(false, true); gc.DeselectAllBeforePostSelect = false; gc.Get(); if (gc.CommandResult() != Result.Success) { return(gc.CommandResult()); } var curve = gc.Object(0).Curve(); if (null == curve) { return(Result.Failure); } var tol = doc.ModelAbsoluteTolerance; var rc = Intersection.CurveBrepFace(curve, face, tol, out Curve[] outCurves, out Point3d[] outPoints);
//this is where the logic of the command is defined protected override Result RunCommand(RhinoDoc doc, RunMode mode) { List <RhinoObject> objs = new List <RhinoObject>(); using (GetObject getter = new GetObject()) { getter.EnablePreSelect(true, false); getter.SetCommandPrompt("Select the objects whose tags you need to delete"); getter.GroupSelect = true; getter.GetMultiple(1, 0); if (getter.CommandResult() != Result.Success) { return(getter.CommandResult()); } for (int i = 0; i < getter.ObjectCount; i++) { objs.Add(getter.Object(i).Object()); } } string tagName; using (GetString getter = new GetString()) { getter.SetCommandPrompt("Enter the tag"); if (getter.Get() != GetResult.String) { RhinoApp.WriteLine("Invalid Input for tag"); return(getter.CommandResult()); } tagName = getter.StringResult(); //Debug.WriteLine(tagName, "Tag"); } doc.Objects.UnselectAll(); TagUtil.DeleteTag(ref objs, tagName, true); //marking the document as dirty - i.e. modified so that it prompts the user to save when closed without saving doc.Modified = true; return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Check the selected dot GetObject go = new GetObject(); 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.Point | Rhino.DocObjects.ObjectType.Annotation; go.SetCommandPrompt("Select Label and a point:"); GetResult result = go.GetMultiple(2, -1); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount); Point pt = null; TextEntity textEntity = null; int pointCounter = 0; int textCounter = 0; // Loop through all the objects to find Text for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (rhinoObject.ObjectType == ObjectType.Annotation) { textEntity = rhinoObject.Geometry as TextEntity; if (textEntity != null && textCounter == 0) { textCounter++; } } else if (rhinoObject.ObjectType == ObjectType.Point) { pt = rhinoObject.Geometry as Point; if (pt != null && pointCounter == 0) { pointCounter++; } } } //if (go.Object(0).Point() != null && go.Object(1).TextEntity() != null) //{ // pt = go.Object(0).Point(); // textEntity = go.Object(1).TextEntity(); //} //else if (go.Object(1).Point() != null && go.Object(0).TextEntity() != null) //{ // pt = go.Object(1).Point(); // textEntity = go.Object(0).TextEntity(); //} //else //{ // RhinoApp.WriteLine("Two of the same objects are selected."); // return Result.Failure; //} if (textCounter > 1) { RhinoApp.WriteLine("More than one text has been selected."); } if (pointCounter > 1) { RhinoApp.WriteLine("More than one point has been selected."); } if (pt != null && textEntity != null) { drawDotMatrix(pt.Location, textEntity.Text, Properties.Settings.Default.DotMatrixHeight); } doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// Creates the layout. /// </summary> /// <param name="doc">The document.</param> /// <param name="panel">The panel.</param> /// <param name="panelParas">The panel paras.</param> /// <returns></returns> public Result createLayout(RhinoDoc doc, FoldedPerforationPanel panel, PanelParameters panelParas) { if (panelParas == null) { panelParas = new PanelParameters(); } if (panel == null) { panel = new FoldedPerforationPanel(); } // Get all selected Objects GetObject go = new GetObject(); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.EnableSelPrevious(true); go.EnablePreSelect(true, false); go.EnablePressEnterWhenDonePrompt(false); go.SetCommandPrompt("Select items for the new layout:"); // Disable the scaling RhinoApp.RunScript("_-DocumentProperties AnnotationStyles ModelSpaceScaling=Disabled LayoutSpaceScaling=Disabled _Enter _Enter", true); GetResult result = go.GetMultiple(1, -1); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } RhinoApp.WriteLine("Total Objects Selected: {0}", go.ObjectCount); string labelName = panel.PartName; string area = string.Format("{0:0.00}", panel.Area); Point2d minPoint = new Point2d(0, 0); Point2d maxPoint = new Point2d(0, 0); // Loop through all the objects to find Text for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bBox = go.Object(i).Object().Geometry.GetBoundingBox(true); if (bBox.Min.X < minPoint.X) { minPoint.X = bBox.Min.X; } if (bBox.Min.Y < minPoint.Y) { minPoint.Y = bBox.Min.Y; } if (bBox.Max.X > maxPoint.X) { maxPoint.X = bBox.Max.X; } if (bBox.Max.Y > maxPoint.Y) { maxPoint.Y = bBox.Max.Y; } } // If the selected items has no label, return failure if (labelName == null) { return(Rhino.Commands.Result.Failure); } // Hide all the non selected objects foreach (var obj in doc.Objects) { if (obj.IsSelected(true) == 0) { doc.Objects.Hide(obj, false); } } // Add layout doc.PageUnitSystem = Rhino.UnitSystem.Millimeters; RhinoView currentView = doc.Views.ActiveView; var pageview = doc.Views.AddPageView(string.Format("{0}", labelName), 210, 297); Point2d bottomLeft = new Point2d(10, 70); Point2d topRight = new Point2d(200, 287); if (pageview != null) { pageview.SetPageAsActive(); var detail = pageview.AddDetailView("Panel", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top); // Show all objects RhinoApp.RunScript("_-Show _Enter", true); if (detail != null) { pageview.SetActiveDetail(detail.Id); doc.Views.ActiveView = pageview; //doc.Views.Redraw(); // Select all the objects for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); rhinoObject.Select(true); } // Hide all the non selected objects var filter = new ObjectEnumeratorSettings { NormalObjects = true, LockedObjects = false, HiddenObjects = false, ActiveObjects = true, ReferenceObjects = true }; var rh_objects = doc.Objects.FindByFilter(filter); pageview.SetPageAsActive(); //doc.Views.Redraw(); foreach (var rh_obj in rh_objects) { var select = 0 == rh_obj.IsSelected(false) && rh_obj.IsSelectable(); rh_obj.Select(select); } RhinoApp.RunScript("_-HideInDetail Enter", true); detail.IsActive = false; } bottomLeft = new Point2d(10, 40); topRight = new Point2d(135, 70); detail = pageview.AddDetailView("Sample", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top); // doc.Views.Redraw(); pageview.SetActiveDetail(detail.Id); detail.Viewport.SetCameraLocation(new Point3d(50, 160, 0), true); detail.CommitViewportChanges(); // doc.Views.Redraw(); detail.DetailGeometry.IsProjectionLocked = true; detail.DetailGeometry.SetScale(4.5, doc.ModelUnitSystem, 1, doc.PageUnitSystem); detail.CommitChanges(); // doc.Views.Redraw(); detail.IsActive = true; pageview.SetActiveDetail(detail.Id); RhinoApp.WriteLine("Name = {0}: Width = {1}, Height = {2}", detail.Viewport.Name, detail.Viewport.Size.Width, detail.Viewport.Size.Height); detail.CommitViewportChanges(); // doc.Views.Redraw(); detail.IsActive = false; bottomLeft = new Point2d(5, 5); topRight = new Point2d(205, 35); detail = pageview.AddDetailView("Block", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top); // doc.Views.Redraw(); detail.IsActive = true; pageview.SetActiveDetail(detail.Id); detail.Viewport.SetCameraLocation(new Point3d(105, 520, 0), true); detail.CommitViewportChanges(); // doc.Views.Redraw(); detail.DetailGeometry.IsProjectionLocked = true; detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 1, doc.PageUnitSystem); detail.CommitChanges(); detail.IsActive = false; // doc.Views.Redraw(); drawBlock(doc, labelName, area, panel.PanelNumber, panelParas); // doc.Views.Redraw(); } // Show all objects RhinoApp.RunScript("_-Show _Enter", true); doc.Views.DefaultViewLayout(); doc.Views.ActiveView = currentView; return(Result.Success); }
/// <summary> /// Runs the command /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Select objects to orient var go = new GetObject(); go.SetCommandPrompt("Select objects to orient"); go.SubObjectSelect = false; go.GroupSelect = true; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } // Point to orient from var gp = new GetPoint(); gp.SetCommandPrompt("Point to orient from"); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } // Define source plane var view = gp.View(); if (view == null) { view = doc.Views.ActiveView; if (view == null) { return(Result.Failure); } } var plane = view.ActiveViewport.ConstructionPlane(); plane.Origin = gp.Point(); // Curve to orient on var gc = new GetObject(); gc.SetCommandPrompt("Curve to orient on"); gc.GeometryFilter = ObjectType.Curve; gc.EnablePreSelect(false, true); gc.DeselectAllBeforePostSelect = false; gc.Get(); if (gc.CommandResult() != Result.Success) { return(gc.CommandResult()); } var objref = gc.Object(0); var obj = objref.Object(); var curve = objref.Curve(); if (obj == null || curve == null) { return(Result.Failure); } // Unselect curve obj.Select(false); // Point on surface to orient to var gx = new GetOrientPerpendicularPoint(curve, plane, go.Object(0).Object()); gx.SetCommandPrompt("New base point on curve"); gx.Get(); if (gx.CommandResult() != Result.Success) { return(gx.CommandResult()); } // One final calculation var xform = new Transform(1); if (gx.CalculateTransform(gx.View().ActiveViewport, gx.Point(), ref xform)) { doc.Objects.Transform(go.Object(0).Object(), xform, true); doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Select planar surface var gs = new GetObject(); gs.SetCommandPrompt("Select planar surface"); gs.GeometryFilter = ObjectType.Surface; gs.SubObjectSelect = false; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } var brep_ref = gs.Object(0); var brep = brep_ref.Brep(); if (null == brep) { return(Result.Failure); } // Verify underlying surface is a PlaneSurface var plane_surface = brep.Faces[0].UnderlyingSurface() as PlaneSurface; if (null == plane_surface) { return(Result.Nothing); } // Select trimming curves on planar surface var gc = new GetObject(); gc.SetCommandPrompt("Select trimming curves on planar surface"); gc.GeometryFilter = ObjectType.Curve; gc.GroupSelect = true; gc.SubObjectSelect = false; gc.EnablePreSelect(false, true); gc.DeselectAllBeforePostSelect = false; gc.GetMultiple(1, 0); if (gc.CommandResult() != Result.Success) { return(gc.CommandResult()); } // Make a copy of the selected Brep var new_brep = new Brep(); new_brep.Append(brep); // Add each selected curve a a inner planar face loop var boundary = new Curve[1]; for (var i = 0; i < gc.ObjectCount; i++) { var curve = gc.Object(i).Curve(); if (null != curve) { boundary[0] = curve; new_brep.Loops.AddPlanarFaceLoop(0, BrepLoopType.Inner, boundary); } } new_brep.Compact(); // IF all is well, then replace the selecte Brep with our new one if (new_brep.IsValid) { doc.Objects.Replace(brep_ref.ObjectId, new_brep); doc.Views.Redraw(); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. GetObject go = new GetObject(); 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; go.SetCommandPrompt("Select All circles you want to filter:"); GetResult result = go.GetMultiple(1, 0); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } int fixingHoleCounter = go.ObjectCount; RhinoApp.WriteLine("circle selection counter = {0}", fixingHoleCounter); int i = 0; Point3d[] fixingHole = new Point3d[fixingHoleCounter]; double[] fixingHoleD = new double[fixingHoleCounter]; RhinoObject[] references = new RhinoObject[fixingHoleCounter]; for (i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); Curve curve = (new ObjRef(rhinoObject)).Curve(); if (curve == null) { continue; } if (curve.IsClosed == false) { continue; } if (curve.IsPlanar() == false) { continue; } if (curve.IsCircle()) { BoundingBox boundingBox = curve.GetBoundingBox(true); fixingHoleD[i] = boundingBox.Max.X - boundingBox.Min.X; fixingHole[i] = boundingBox.Center; references[i] = rhinoObject; } } //Get the gap clearance offset go.SetCommandPrompt("Enter detection radius:"); go.AcceptNumber(true, false); go.Get(); double offset = go.Number(); double perforationHoldD; string layerName = ""; //for testing purpose, draw the hole with offset using red color /*Curve[] circles = new Curve[fixingHole.Length]; * for (i = 0; i < circles.Length; i++) * { * * circles[i] = new ArcCurve(new Circle(fixingHole[i], offset)); * } * * * if (circles != null) * { * layerName = offset + "mm GAP CLEARANCE"; * RhinoUtilities.SetActiveLayer(layerName, System.Drawing.Color.Red); * * foreach (Curve cv in circles) * { * Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(cv); * } * }*/ string clashHoleLayerName = "HOLES CLASHED"; Layer clashHoleLayer = new Layer(); clashHoleLayer.Name = clashHoleLayerName; clashHoleLayer.Color = System.Drawing.Color.Red; int clashHoleLayerIndex = doc.Layers.Add(clashHoleLayer); int currentHoleCounter; int flag; bool[] deletedCircles = new bool[fixingHole.Length]; for (i = 0; i < deletedCircles.Length; i++) { deletedCircles[i] = false; } Curve circles; RhinoUtilities.SetActiveLayer(clashHoleLayerName, System.Drawing.Color.Red); for (i = 0; i < fixingHole.Length - 1; i++) { currentHoleCounter = 0; flag = 0; for (int j = i + 1; j < fixingHole.Length; j++) { if (deletedCircles[j] == true) { continue; } if (fixingHole[i].DistanceTo(fixingHole[j]) < fixingHoleD[i] + offset) { if (currentHoleCounter == 0) { flag = j; currentHoleCounter++; } else { currentHoleCounter++; break; } } if (currentHoleCounter == 1) { circles = new ArcCurve(new Circle(fixingHole[flag], fixingHoleD[flag] / 2)); Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(circles); RhinoDoc.ActiveDoc.Objects.Delete(references[flag], false); deletedCircles[flag] = true; } else if (currentHoleCounter == 2) { circles = new ArcCurve(new Circle(fixingHole[i], fixingHoleD[i] / 2)); Guid guid = RhinoDoc.ActiveDoc.Objects.AddCurve(circles); RhinoDoc.ActiveDoc.Objects.Delete(references[i], false); deletedCircles[i] = true; } } } RhinoUtilities.setLayerVisibility("HOLES CLASHED", true); RhinoUtilities.setLayerVisibility(layerName, false); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Check the selected dot GetObject go = new GetObject(); // Create a new dictionary of strings, with string keys. // Dictionary <double, double> sizeAngle = new Dictionary <double, double>(); List <double> holeSizeList = new List <double>(); 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; go.SetCommandPrompt("Select all the circles:"); GetResult result = go.GetMultiple(1, -1); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } RhinoApp.WriteLine("Object selection counter = {0}", go.ObjectCount); List <RhinoObject> rhinoObjectList = new List <RhinoObject>(); List <ArcCurve> arcCurveList = new List <ArcCurve>(); // Loop through all the objects to find Text for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (rhinoObject.ObjectType == ObjectType.Curve) { ArcCurve curve = rhinoObject.Geometry as ArcCurve; if (curve != null) { if (curve.IsCircle() == true) { if (!holeSizeList.Exists(element => element == curve.Radius)) { holeSizeList.Add(curve.Radius); } arcCurveList.Add(curve); // rhinoObjectList.Add(rhinoObject); } } } } holeSizeList.Sort(); if (holeSizeList.Count < 1) { return(Result.Failure); } double maxHole = holeSizeList.Max(); double minHole = holeSizeList.Min(); foreach (double size in holeSizeList) { double angle; if ((maxHole - minHole) != 0) { angle = 180 * ((size - minHole) / (maxHole - minHole)); } else { angle = 0; } sizeAngle.Add(size, angle); } // Create a new layer string layerName = "FormTool"; // Does a layer with the same name already exist? int layerIndex = doc.Layers.Find(layerName, true); // If layer does not exist if (layerIndex == -1) { // Add a new layer to the document layerIndex = doc.Layers.Add(layerName, System.Drawing.Color.Black); } doc.Layers.SetCurrentLayerIndex(layerIndex, true); foreach (ArcCurve ac in arcCurveList) { double angle = 0; sizeAngle.TryGetValue(ac.Radius, out angle); drawFormTool(ac.Arc.Center.X, ac.Arc.Center.Y, angle * Math.PI / 180); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType geometry_filter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh; var integer1 = 300; var integer2 = 300; var option_integer1 = new OptionInteger(integer1, 200, 900); var option_integer2 = new OptionInteger(integer2, 200, 900); var go = new GetObject(); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GeometryFilter = geometry_filter; go.AddOptionInteger("Option1", ref option_integer1); go.AddOptionInteger("Option2", ref option_integer2); go.GroupSelect = true; go.SubObjectSelect = false; var have_preselected_objects = false; while (true) { var res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); go.AlreadySelectedObjectSelect = true; go.EnableClearObjectsOnEntry(false); go.DeselectAllBeforePostSelect = false; go.EnableUnselectObjectsOnExit(false); continue; } if (res != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { have_preselected_objects = true; go.EnablePreSelect(false, true); go.AlreadySelectedObjectSelect = true; go.EnableClearObjectsOnEntry(false); go.DeselectAllBeforePostSelect = false; go.EnableUnselectObjectsOnExit(false); continue; } break; } if (have_preselected_objects) { // 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 (var i = 0; i < go.ObjectCount; i++) { var rhino_object = go.Object(i).Object(); rhino_object?.Select(false); } doc.Views.Redraw(); } var object_count = go.ObjectCount; integer1 = option_integer1.CurrentValue; integer2 = option_integer2.CurrentValue; RhinoApp.WriteLine("Select object count: {0}", object_count); RhinoApp.WriteLine("Value of integer1: {0}", integer1); RhinoApp.WriteLine("Value of integer2: {0}", integer2); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gp = new GetObject(); gp.SetCommandPrompt("Select points to project"); gp.GeometryFilter = ObjectType.Point; gp.GetMultiple(1, 0); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } var gm = new GetObject(); gm.SetCommandPrompt("Select mesh to project onto"); gm.GeometryFilter = ObjectType.Mesh; gm.SubObjectSelect = false; gm.EnablePreSelect(false, true); gm.DeselectAllBeforePostSelect = false; gm.Get(); if (gm.CommandResult() != Result.Success) { return(gm.CommandResult()); } var mesh = gm.Object(0).Mesh(); if (null == mesh) { return(Result.Failure); } var meshes = new List <Mesh>(1) { mesh }; var points = new List <Point3d>(gp.ObjectCount); for (var i = 0; i < gp.ObjectCount; i++) { var point = gp.Object(i).Point(); if (null != point) { points.Add(point.Location); } } var dir = -Vector3d.ZAxis; var tol = doc.ModelAbsoluteTolerance; int[] indices; var project_points = Intersection.ProjectPointsToMeshesEx(meshes, points, dir, tol, out indices); if (null != project_points) { for (int i = 0; i < project_points.Length; i++) { doc.Objects.AddPoint(project_points[i]); doc.Objects.AddLine(project_points[i], points[indices[i]]); } } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { using (var go = new GetObject()) { go.SetCommandPrompt("Please select closed objects for converting to Honeybee Room"); //Only Brep is accepted, because we need to save meta data to sub-surface as well. //Extrusion doesn't have sub-surface. //all extrusion will be converted to Brep. go.GeometryFilter = ObjectType.Brep | ObjectType.Extrusion; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; //check if any brep has been converted to Room var optionSkipExistingRoom_toggle = new OptionToggle(true, "No_RecreateAllRooms", "Yes"); while (true) { go.ClearCommandOptions(); go.AddOptionToggle("SkipExistingRoom", ref optionSkipExistingRoom_toggle); var rc = go.GetMultiple(1, 0); if (rc == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (rc != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); continue; } break; } if (go.CommandResult() != Result.Success) { return(Result.Failure); } if (go.ObjectCount == 0) { return(Result.Nothing); } var ifSkip = optionSkipExistingRoom_toggle.CurrentValue; //Getting objects var solidBreps = go.Objects().Where(_ => _.Brep() != null).Where(_ => _.Brep().IsSolid); var objectToConvert = solidBreps; if (ifSkip) { objectToConvert = solidBreps.Where(_ => !_.IsRoom()).ToList(); } ConvertToRoom(doc, objectToConvert); doc.Views.Redraw(); var count = objectToConvert.Count(); var msg = count > 1 ? $"{count} Honeybee rooms were created successfully!" : $"{count} Honeybee room was created successfully!"; RhinoApp.WriteLine(msg); return(Result.Success); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType geometryFilter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh; GetObject go = new GetObject(); 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 (; ;) // infinite loop { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } 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 objectCount = go.ObjectCount; List <String> objectTypeList = new List <string>(); List <String> objectNameList = new List <string>(); for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); string objectName = rhinoObject.Name; if (null != rhinoObject) { objectTypeList.Add(rhinoObject.ObjectType.ToString()); objectNameList.Add(objectName); } } RhinoApp.WriteLine(string.Format("Select object count = {0}", objectCount)); for (int i = 0; i < objectTypeList.Count; i++) { RhinoApp.WriteLine(string.Format("Select object Name : {0}, Type : {1}", objectNameList[i], objectTypeList[i])); } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Command variables var selectedObjects = new List <RhinoObject>(); string selectedSchema = ""; bool automatic = true; bool directShape = false; // Construct an objects getter // This includes an option toggle for "Automatic" (true means automagic schema application, no directshapes) var getObj = new GetObject(); getObj.SetCommandPrompt("Select geometry"); var toggleAutomatic = new OptionToggle(true, "Off", "On"); getObj.AddOptionToggle("Automatic", ref toggleAutomatic); getObj.GroupSelect = true; getObj.SubObjectSelect = false; getObj.EnableClearObjectsOnEntry(false); getObj.EnableUnselectObjectsOnExit(false); getObj.DeselectAllBeforePostSelect = false; // Get objects for (; ;) { GetResult res = getObj.GetMultiple(1, 0); if (res == GetResult.Option) { getObj.EnablePreSelect(false, true); continue; } else if (res != GetResult.Object) { return(Result.Cancel); } if (getObj.ObjectsWerePreselected) { getObj.EnablePreSelect(false, true); continue; } break; } selectedObjects = getObj.Objects().Select(o => o.Object()).ToList(); automatic = toggleAutomatic.CurrentValue; // Construct an options getter if "Automatic" was set to "off" if (!automatic) { // Construct an options getter for schema options // This includes an option toggle for "DirectShape" (true will asign selected schema as the family) // Also includes an option list of supported schemas var getOpt = new GetOption(); getOpt.SetCommandPrompt("Select schema options. Press Enter when done"); var toggleDirectShape = new OptionToggle(false, "Off", "On"); var directShapeIndex = getOpt.AddOptionToggle("DirectShape", ref toggleDirectShape); List <string> schemas = Enum.GetNames(typeof(SchemaObjectFilter.SupportedSchema)).ToList(); int schemaListOptionIndex = getOpt.AddOptionList("Schema", schemas, 0); // Get options while (getOpt.Get() == GetResult.Option) { if (getOpt.OptionIndex() == schemaListOptionIndex) { selectedSchema = schemas[getOpt.Option().CurrentListOptionIndex]; } if (getOpt.OptionIndex() == directShapeIndex) { directShape = toggleDirectShape.CurrentValue; } } } // Apply schemas if (automatic) { ApplySchemas(selectedObjects, doc); } else { ApplySchema(selectedObjects, selectedSchema, doc, directShape); } return(Result.Success); }