public static Result PrePostPick(RhinoDoc doc) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects"); go.EnablePreSelect(true, true); go.EnablePostSelect(true); go.GetMultiple(0, 0); if (go.CommandResult() != Result.Success) return go.CommandResult(); var selected_objects = go.Objects().ToList(); if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); go.DeselectAllBeforePostSelect = false; go.EnableUnselectObjectsOnExit(false); go.GetMultiple(0, 0); if (go.CommandResult() == Result.Success) { foreach (var obj in go.Objects()) { selected_objects.Add(obj); // The normal behavior of commands is that when they finish, // objects that were pre-selected remain selected and objects // that were post-selected will not be selected. Because we // potentially could have both, we'll try to do something // consistent and make sure post-selected objects also stay selected obj.Object().Select(true); } } } return selected_objects.Count > 0 ? Result.Success : Result.Nothing; }
public static Result MeshVolume(RhinoDoc doc) { var gm = new GetObject(); gm.SetCommandPrompt("Select solid meshes for volume calculation"); gm.GeometryFilter = ObjectType.Mesh; gm.GeometryAttributeFilter = GeometryAttributeFilter.ClosedMesh; gm.SubObjectSelect = false; gm.GroupSelect = true; gm.GetMultiple(1, 0); if (gm.CommandResult() != Result.Success) return gm.CommandResult(); double volume = 0.0; double volume_error = 0.0; foreach (var obj_ref in gm.Objects()) { if (obj_ref.Mesh() != null) { var mass_properties = VolumeMassProperties.Compute(obj_ref.Mesh()); if (mass_properties != null) { volume += mass_properties.Volume; volume_error += mass_properties.VolumeError; } } } RhinoApp.WriteLine("Total volume = {0:f} (+/- {1:f})", volume, volume_error); return Result.Success; }
public static Rhino.Commands.Result CircleCenter(Rhino.RhinoDoc doc) { Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GeometryAttributeFilter = Rhino.Input.Custom.GeometryAttributeFilter.ClosedCurve; go.GetMultiple(1, 0); if( go.CommandResult() != Rhino.Commands.Result.Success ) return go.CommandResult(); Rhino.DocObjects.ObjRef[] objrefs = go.Objects(); if( objrefs==null ) return Rhino.Commands.Result.Nothing; double tolerance = doc.ModelAbsoluteTolerance; for( int i=0; i<objrefs.Length; i++ ) { // get the curve geometry Rhino.Geometry.Curve curve = objrefs[i].Curve(); if( curve==null ) continue; Rhino.Geometry.Circle circle; if( curve.TryGetCircle(out circle, tolerance) ) { Rhino.RhinoApp.WriteLine("Circle{0}: center = {1}", i+1, circle.Center); } } return Rhino.Commands.Result.Success; }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { Rhino.Input.Custom.GetObject getobjects = new Rhino.Input.Custom.GetObject(); getobjects.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; getobjects.AcceptNothing(false); switch (getobjects.GetMultiple(1, 0)) { case GetResult.ExitRhino: return(Result.ExitRhino); case GetResult.Cancel: return(Result.Cancel); case GetResult.Object: if (getobjects.ObjectCount > 1) { Rhino.DocObjects.ObjRef[] arrCurve = getobjects.Objects(); Array.Sort(arrCurve, (x, y) => x.Curve().GetLength().CompareTo(y.Curve().GetLength())); doc.Objects.Delete(arrCurve[0], true); } return(Result.Success); default: return(Result.Failure); } }
public static Result PickPoint(RhinoDoc doc) { // this creates a point where the mouse is clicked. var gp = new GetPoint(); gp.SetCommandPrompt("Click for new point"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var point3d = gp.Point(); doc.Objects.AddPoint(point3d); doc.Views.Redraw(); // selects a point that already exists ObjRef obj_ref; var rc = RhinoGet.GetOneObject("Select point", false, ObjectType.Point, out obj_ref); if (rc != Result.Success) return rc; var point = obj_ref.Point(); RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); doc.Objects.UnselectAll(); // selects multiple points that already exist ObjRef[] obj_refs; rc = RhinoGet.GetMultipleObjects("Select point", false, ObjectType.Point, out obj_refs); if (rc != Result.Success) return rc; foreach (var o_ref in obj_refs) { point = o_ref.Point(); RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); } doc.Objects.UnselectAll(); // also selects a point that already exists. // Used when RhinoGet doesn't provide enough control var go = new GetObject(); go.SetCommandPrompt("Select point"); go.GeometryFilter = ObjectType.Point; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) return go.CommandResult(); foreach (var o_ref in go.Objects()) { point = o_ref.Point(); if (point != null) RhinoApp.WriteLine("Point: x:{0}, y:{1}, z:{2}", point.Location.X, point.Location.Y, point.Location.Z); } doc.Views.Redraw(); return Result.Success; }
public static Result CopyGroups(RhinoDoc doc) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to copy in place"); go.GroupSelect = true; go.SubObjectSelect = false; go.GetMultiple(1, 0); if (go.CommandResult() != Result.Success) return go.CommandResult(); var xform = Transform.Identity; var group_map = new Dictionary<int, int>(); foreach (var obj_ref in go.Objects()) { if (obj_ref != null) { var obj = obj_ref.Object(); var duplicate = doc.Objects.Transform(obj_ref.ObjectId, xform, false); RhinoUpdateObjectGroups(ref obj, ref group_map); } } doc.Views.Redraw(); return Result.Success; }
public static Result Loft(RhinoDoc doc) { // select curves to loft var gs = new GetObject(); gs.SetCommandPrompt("select curves to loft"); gs.GeometryFilter = ObjectType.Curve; gs.DisablePreSelect(); gs.SubObjectSelect = false; gs.GetMultiple(2, 0); if (gs.CommandResult() != Result.Success) return gs.CommandResult(); var curves = gs.Objects().Select(obj => obj.Curve()).ToList(); var breps = Brep.CreateFromLoft(curves, Point3d.Unset, Point3d.Unset, LoftType.Tight, false); foreach (var brep in breps) doc.Objects.AddBrep(brep); doc.Views.Redraw(); return Result.Success; }
public static Result EdgeSrf(RhinoDoc doc) { var go = new GetObject(); go.SetCommandPrompt("Select 2, 3, or 4 open curves"); go.GeometryFilter = ObjectType.Curve; go.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve; go.GetMultiple(2, 4); if (go.CommandResult() != Result.Success) return go.CommandResult(); var curves = go.Objects().Select(o => o.Curve()); var brep = Brep.CreateEdgeSurface(curves); if (brep != null) { doc.Objects.AddBrep(brep); doc.Views.Redraw(); } return Result.Success; }
//Creates reinforcement objects and saves them into the selected point as userData public static Reinforcement[] CreateReinforcements(string mName, double diam) { RhinoDoc doc = RhinoDoc.ActiveDoc; //Allow user to pick multiple objects const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Point; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject() { GeometryFilter = geometryFilter, GroupSelect = true, SubObjectSelect = false, DeselectAllBeforePostSelect = false }; go.SetCommandPrompt("Pick all the points that you want to change to reinforcement."); go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); bool bHavePreselectedObjects = false; for (;;) { Rhino.Input.GetResult res = go.GetMultiple(1, 0); if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } //Unselects the preselected objects 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 = GetOrCreateLayer(doc, "Reinforcement", Color.Black); if (layerIndex == 999) { return new Reinforcement[] {} } ; Reinforcement[] reinfList = { }; //Create reinforcement objects for each selected points ObjRef[] objects = go.Objects(); if (objects != null) { reinfList = CreateReinfObjs(doc, objects, layerIndex, mName, diam); } return(reinfList); }
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 { Material = new SteelMaterial("B500B"), BasePoint = 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); }