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); } } } }
/// <summary> /// Getter method to load primal/dual from a geometry container from the Rhino Document /// </summary> /// <param name="primal">provided primal - need to check if it has data after the method ends</param> /// <param name="dual">provided primal - just like primal check if it has cells </param> public static IList <Guid> LoadPrimalDual(out PFoam primal, out PFoam dual, out ContainerType container, bool connect = true) { primal = new PFoam(); dual = new PFoam(); container = ContainerType.Edge; GetObject getObj = new GetObject(); var togGeoUpdate = new OptionToggle(true, "no", "yes"); var togClearConstraints = new OptionToggle(false, "no", "yes"); //var togOptionReplace = new OptionToggle(true, "Keep", "Replace"); getObj.SetCommandPrompt("Pick the geometry container (group of lines, surfaces, polysurfaces or meshes)"); getObj.AddOptionToggle("UpdateGeo", ref togGeoUpdate); getObj.AddOptionToggle("ClearConstraints", ref togClearConstraints); //getObj.AddOptionToggle("ReplaceGeo", ref togOptionReplace); getObj.GroupSelect = true; getObj.GeometryFilter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Mesh; while (true) { var r = getObj.GetMultiple(1, 0); if (r == GetResult.Cancel) { return(new List <Guid>()); } else if (r == GetResult.Object) { break; } } var guids = getObj.Objects().Select(x => x.ObjectId).ToList(); var geoObj = getObj.Objects().Select(x => x.Geometry()); if (geoObj.All(x => x.ObjectType == Rhino.DocObjects.ObjectType.Brep)) { var brepInput = geoObj.Cast <Brep>().ToList(); if (brepInput.Any(x => x.Faces.Count > 1)) { container = ContainerType.CellBrep; } else { container = ContainerType.FaceBrep; } primal = LoadData.LoadFromFaces(brepInput, out dual, togGeoUpdate.CurrentValue); } else if (geoObj.All(x => x.ObjectType == Rhino.DocObjects.ObjectType.Curve)) { container = ContainerType.Edge; var curveGeos = geoObj.Cast <Curve>().ToList(); primal = LoadData.LoadFromEdges(curveGeos, out dual, togGeoUpdate.CurrentValue); } else if (geoObj.All(x => x.ObjectType == Rhino.DocObjects.ObjectType.Mesh)) { var meshGeos = geoObj.Cast <Mesh>().ToList(); if (meshGeos.Any(x => x.Ngons.Count > 1 || (x.Ngons.Count == 0 && x.Faces.Count > 1) || (x.Ngons.Count == 1 && x.Faces.Count > x.Ngons[0].FaceCount))) { container = ContainerType.CellMesh; } else { container = ContainerType.FaceMesh; } primal = LoadData.LoadFromMeshes(meshGeos, out dual, togGeoUpdate.CurrentValue); } else { Rhino.RhinoApp.WriteLine("Mixed data detected!"); return(new List <Guid>()); } if (primal.Cells.Count < 1) { Rhino.RhinoApp.WriteLine("Error creating primal from provided data!"); return(new List <Guid>()); } if (connect && dual.Cells.Count > 1 && primal.Dual.Id == dual.Id) { Util.ConnectDuals(ref primal, ref dual); } if (togClearConstraints.CurrentValue) { foreach (var vert in primal.Vertices) { vert.RestrictPosition = null; vert.RestrictSupport = null; vert.SupportGuid = Guid.Empty; } foreach (var edge in primal.Edges) { edge.TargetLength = double.NaN; edge.MaxLength = double.MaxValue; edge.MinLength = double.Epsilon; } foreach (var face in primal.Faces) { face.TargetArea = double.NaN; } } Rhino.RhinoDoc.ActiveDoc.Objects.UnselectAll(); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); return(guids); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var cs_option = new OptionToggle(m_use_cplane, "World", "CPlane"); var go = new GetObject(); go.SetCommandPrompt("Select objects for bounding box calculation"); go.GroupSelect = true; go.SubObjectSelect = false; for (;;) { go.ClearCommandOptions(); go.AddOptionToggle("CoordinateSystem", ref cs_option); var res = go.GetMultiple(1, 0); if (res == GetResult.Option) { continue; } else if (res != GetResult.Object) { return(Result.Cancel); } break; } var plane = go.View().ActiveViewport.ConstructionPlane(); m_use_cplane = cs_option.CurrentValue; var world_to_plane = new Transform(1.0); if (m_use_cplane) { world_to_plane = Transform.ChangeBasis(Plane.WorldXY, plane); } var bounding_box = new BoundingBox(); for (var i = 0; i < go.ObjectCount; i++) { var rhino_obj = go.Object(i).Object(); if (null != rhino_obj) { var box = rhino_obj.Geometry.GetBoundingBox(world_to_plane); if (box.IsValid) { if (i == 0) { bounding_box = box; } else { bounding_box.Union(box); } } } } if (!bounding_box.IsValid) { RhinoApp.WriteLine("BoundingBox failed. Unable to calculate bounding box."); return(Result.Failure); } var box_corners = new Point3d[8]; box_corners[0] = bounding_box.Corner(false, false, false); box_corners[1] = bounding_box.Corner(true, false, false); box_corners[2] = bounding_box.Corner(true, true, false); box_corners[3] = bounding_box.Corner(false, true, false); box_corners[4] = bounding_box.Corner(false, false, true); box_corners[5] = bounding_box.Corner(true, false, true); box_corners[6] = bounding_box.Corner(true, true, true); box_corners[7] = bounding_box.Corner(false, true, true); if (m_use_cplane) { // Transform corners points from cplane coordinates // to world coordinates if necessary. var plane_to_world = Transform.ChangeBasis(plane, Plane.WorldXY); for (var i = 0; i < 8; i++) { box_corners[i].Transform(plane_to_world); } } Point3d[] rect; var type = ClassifyBoundingBox(box_corners, out rect); if (type == BoundingBoxClassification.Point) { RhinoApp.WriteLine("BoundingBox failed. The bounding box is a point."); } else if (type == BoundingBoxClassification.Line) { RhinoApp.WriteLine("BoundingBox failed. The bounding box is a line."); } else if (type == BoundingBoxClassification.Rectangle) { doc.Objects.AddPolyline(rect); } else //if (type == BoundingBoxClassification.Box) { var brep = Brep.CreateFromBox(box_corners); doc.Objects.AddBrep(brep); } doc.Views.Redraw(); 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); }
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); } }
public IList <PFVertex> PickVertex() { var innerVerts = Vertices.Where(x => !x.External); var pickedVerts = new List <PFVertex>(); var doc = Rhino.RhinoDoc.ActiveDoc; var vertexConduit = new DrawPFVertexConduit(innerVerts) { Enabled = true }; doc.Views.Redraw(); var gVert = new GetPFVertex(innerVerts); //var permOption = new OptionToggle(false, "temp", "perm"); gVert.AddSnapPoints(innerVerts.Select(x => x.Point).ToArray()); while (true) { gVert.SetCommandPrompt("select Vertex points. (<ESC> to exit"); //gVert.AddOptionToggle("Remember", ref permOption); gVert.AcceptNothing(true); gVert.AcceptString(true); //gVert.SetCursor() // this we can change after switching to Rhino 6 - api gVert.SetDefaultString($"({pickedVerts.Count}) vertices selected press <Enter> to accept"); gVert.Get(true); doc.Views.Redraw(); var result = gVert.CommandResult(); var strResult = gVert.StringResult(); pickedVerts = new List <PFVertex>(); if (gVert.CommandResult() == Rhino.Commands.Result.Cancel) { break; } foreach (var vrt in innerVerts) { if (vrt.Picked) { pickedVerts.Add(vrt); } } if (gVert.GotDefault()) { // here use a pick mechanism to get the geometry if (pickedVerts.Count > 0) { var outside = new OptionToggle(true, "true", "false"); var fixPoint = new OptionToggle(false, "constrain", "fix"); var getRefGeo = new GetObject(); getRefGeo.SetCommandPrompt("Pick the constrain object for the selected vertices"); getRefGeo.AddOptionToggle("Outside", ref outside); getRefGeo.AddOptionToggle("Fixed", ref fixPoint); getRefGeo.AcceptNothing(true); getRefGeo.DisablePreSelect(); if (getRefGeo.Get() == Rhino.Input.GetResult.Object) { var geoGet = getRefGeo.Object(0); var idGet = getRefGeo.Object(0).ObjectId; SetVertexConstraints(pickedVerts, geoGet.Object(), 1, outside.CurrentValue); } else if (getRefGeo.Result() == Rhino.Input.GetResult.Nothing) { foreach (var vert in pickedVerts) { vert.RestrictPosition = null; vert.RestrictSupport = null; vert.SupportGuid = Guid.Empty; } } else if (getRefGeo.Result() == Rhino.Input.GetResult.Option && fixPoint.CurrentValue == true) { foreach (var vert in pickedVerts) { vert.RestrictPosition = vert.ConstrainPoint; vert.RestrictSupport = new Rhino.Geometry.Point(vert.Point); // this is what keeps the vertex in place vert.InfluenceCoef = 100; // this is what makes it relatively immovable vert.SupportGuid = Guid.Empty; vert.Fixed = true; // this is just for serilization refference } } doc.Objects.UnselectAll(); pickedVerts.ForEach(x => x.Picked = false); doc.Views.Redraw(); } else { break; } } } vertexConduit.Enabled = false; doc.Views.Redraw(); return(pickedVerts); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //look at this for a summary of all the GET commands. // https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Input_Custom_GetBaseClass.htm. /*System.Object * Rhino.Input.Custom.GetBaseClass * Rhino.Input.Custom.GetInteger * Rhino.Input.Custom.GetNumber * Rhino.Input.Custom.GetObject * Rhino.Input.Custom.GetOption * Rhino.Input.Custom.GetPoint * Rhino.Input.Custom.GetString * * */ var gc = new GetObject(); gc.SetCommandPrompt("Select objects"); gc.GeometryFilter = ObjectType.AnyObject; OptionInteger intOption = new OptionInteger(1, 1, 99); OptionDouble dblOption = new OptionDouble(2.2, 0, 99); OptionToggle boolOption = new OptionToggle(true, "off", "on"); gc.AddOptionInteger("Integer", ref intOption); gc.AddOptionDouble("Double", ref dblOption); gc.AddOptionToggle("Boolean", ref boolOption); int listIndex = 0; string[] listValues = new string[] { "Bran", "Bob", "Arya", "Sansa", "Rickon" }; int optList = gc.AddOptionList("List", listValues, listIndex); while (true) { GetResult res = gc.GetMultiple(1, 0); //we can check if the user selected something if (gc.CommandResult() != Result.Success) { return(gc.CommandResult()); } if (res == Rhino.Input.GetResult.Object) { RhinoApp.WriteLine("Command line option values are"); RhinoApp.WriteLine("Integer = {0}", intOption.CurrentValue); RhinoApp.WriteLine("Double = {0}", dblOption.CurrentValue); RhinoApp.WriteLine("Boolean = {0}", boolOption.CurrentValue); RhinoApp.WriteLine("List = {0}", listValues[listIndex]); } else if (res == Rhino.Input.GetResult.Option) { if (gc.OptionIndex() == optList) { listIndex = gc.Option().CurrentListOptionIndex; //this updates the list option to whatever index the user has picked } continue; } break; } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //pick surface to orient to or block instance to relocate GetObject gs = new Rhino.Input.Custom.GetObject(); gs.SetCommandPrompt("Surface to orient new object on or BlockInstance to move"); gs.GeometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.InstanceReference; gs.SubObjectSelect = true; gs.DeselectAllBeforePostSelect = false; gs.OneByOnePostSelect = true; gs.Get(); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } Rhino.DocObjects.ObjRef objref = gs.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Result.Failure); } surface = objref.Surface(); //relocate block instance if (surface == null) { Rhino.DocObjects.InstanceObject instance1 = objref.Object() as Rhino.DocObjects.InstanceObject; instancePoint = instance1.InsertionPoint; double g, h; surface2.ClosestPoint(instancePoint, out g, out h); var instanceDirection = surface2.NormalAt(g, h); instancePlane = new Plane(instancePoint, instanceDirection); Rhino.Input.Custom.GetPoint gpss = new Rhino.Input.Custom.GetPoint(); gpss.SetCommandPrompt("Point on surface to orient to"); gpss.Constrain(surface2, false); gpss.DynamicDraw += RefObjDraw; gpss.Tag = instance1; gpss.Get(); if (gpss.CommandResult() != Rhino.Commands.Result.Success) { return(gpss.CommandResult()); } Point3d ptss = gpss.Point(); surface2.ClosestPoint(ptss, out g, out h); var direction1 = surface2.NormalAt(g, h); Plane pl11 = new Plane(ptss, direction1); Transform iform = Rhino.Geometry.Transform.PlaneToPlane(instancePlane, pl11); doc.Objects.Transform(instance1, iform, true); return(Result.Success); } obj.Select(false); //pick objekt to orient var copy = new Rhino.Input.Custom.OptionToggle(false, "No", "Yes"); GetObject go = new GetObject(); go.SetCommandPrompt("Select object to orient."); go.AddOptionToggle("Copy", ref copy); go.SubObjectSelect = true; go.DeselectAllBeforePostSelect = false; go.GroupSelect = true; for (; ;) { var res = go.GetMultiple(1, -1); if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } if (res == GetResult.Option) { copyBol = copy.CurrentValue; continue; } if (gs.CommandResult() != Result.Success) { return(gs.CommandResult()); } break; } int obCount = go.ObjectCount; string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss"); //create block instance and plane for instance Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Point to orient from"); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } Vector3d vt1 = new Vector3d(0, 0, 1); Point3d pt1 = gp.Point(); sourcePlane = new Plane(pt1, vt1); Plane originPlane = new Plane(Point3d.Origin, vt1); Transform bform = Rhino.Geometry.Transform.PlaneToPlane(sourcePlane, originPlane); //block instance GeometryBase[] obj1List = new GeometryBase[obCount]; List <Brep> opList = new List <Brep>(); for (int igo = 0; igo < obCount; igo++) { Rhino.DocObjects.ObjRef objref1 = go.Object(igo); Rhino.DocObjects.RhinoObject obj1 = objref1.Object(); if (obj == null) { return(Result.Failure); } obj.Select(false); Rhino.Geometry.Brep opItem = objref1.Brep(); opList.Add(opItem); GeometryBase obj1Base = obj1.Geometry; obj1Base.Transform(bform); obj1List[igo] = obj1Base; } var orientBlock = doc.InstanceDefinitions.Add("Block" + instDefCount, "OrientBlock", Point3d.Origin, obj1List); //get all go.Objects to .Tag Brep[] op = new Brep[obCount]; op = Brep.CreateBooleanUnion(opList, 0.01); Brep od = new Brep(); od = op[0]; var odGuid = doc.Objects.AddBrep(od); Rhino.DocObjects.ObjRef objref2 = new Rhino.DocObjects.ObjRef(odGuid); Rhino.DocObjects.RhinoObject objDrw = objref2.Object(); //orient plane to surface if (copyBol) { while (true) { Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint(); gps.SetCommandPrompt("Point on surface to orient to. Press enter when done."); gps.Constrain(surface, false); gps.AcceptNothing(true); gps.DynamicDraw += RefObjDraw; gps.Tag = objDrw; var res = gps.Get(); if (res == GetResult.Nothing) { break; } //else if (gps.CommandResult() != Rhino.Commands.Result.Success) // return gps.CommandResult(); Point3d pts = gps.Point(); double u, v; surface.ClosestPoint(pts, out u, out v); Vector3d direction = surface.NormalAt(u, v); Plane pl1 = new Plane(pts, direction); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1); doc.Objects.AddInstanceObject(orientBlock, xform); doc.Objects.Delete(objDrw); } copyBol = false; } else { Rhino.Input.Custom.GetPoint gps = new Rhino.Input.Custom.GetPoint(); gps.SetCommandPrompt("Point on surface to orient to"); gps.Constrain(surface, false); gps.DynamicDraw += RefObjDraw; gps.Tag = objDrw; gps.Get(); if (gps.CommandResult() != Rhino.Commands.Result.Success) { return(gps.CommandResult()); } Point3d pts = gps.Point(); double u, v; surface.ClosestPoint(pts, out u, out v); Vector3d direction = surface.NormalAt(u, v); Plane pl1 = new Plane(pts, direction); Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(originPlane, pl1); doc.Objects.AddInstanceObject(orientBlock, xform); doc.Objects.Delete(objDrw); } surface2 = surface; return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: start here modifying the behaviour of your command. // --- //RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName); GetObject getBreps = new GetObject(); getBreps.SetCommandPrompt("Pick the breps to create a PolyhedralFrame"); getBreps.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; // set up options OptionDouble dblOptionCollapse = new Rhino.Input.Custom.OptionDouble(0.1, true, 0.0); OptionDouble dblOptionPlanar = new Rhino.Input.Custom.OptionDouble(0.1, true, 0.0); OptionToggle togOptionReplace = new OptionToggle(true, "Keep", "Replace"); getBreps.AddOptionDouble("PointCollapseLimit", ref dblOptionCollapse); getBreps.AddOptionDouble("PlanarityMaxDeviation", ref dblOptionPlanar); getBreps.AddOptionToggle("ReplaceGeo", ref togOptionReplace); getBreps.AcceptNothing(false); while (true) { var r = getBreps.GetMultiple(1, 0); if (r == GetResult.Cancel) { return(getBreps.CommandResult()); } else if (r == GetResult.Object) { break; } } List <Guid> ids = new List <Guid>(); for (int i = 0; i < getBreps.ObjectCount; i++) { ids.Add(getBreps.Object(i).ObjectId); } var foam = new PFoam(); var deleteOriginal = false; try { foam.ProcessBFaces(Util.DecomposeG(ids), dblOptionCollapse.CurrentValue, dblOptionPlanar.CurrentValue); doc.Objects.UnselectAll(); if (foam.Faces.Count > 2) { foam.MakeCells(); Point3d newCentroid = foam.Centroid; if (!togOptionReplace.CurrentValue) { Rhino.Input.RhinoGet.GetPoint("Place the PolyFrame", true, out newCentroid); } else { deleteOriginal = true; } //Rhino.RhinoDoc.ActiveDoc.Objects.Delete(ids, true); foam.Offset(newCentroid - foam.Centroid); foam.Show(true, true, false); foam.ShowCells(); if (!foam.SaveToDocument()) { foam.Hide(); return(Result.Cancel); } foam.Hide(); if (deleteOriginal) { Rhino.RhinoDoc.ActiveDoc.Objects.Delete(ids, true); } doc.Views.Redraw(); Rhino.RhinoApp.WriteLine($"Constructed a PolyFrame object with {foam.Cells.Count} cells, {foam.Faces.Count} half-faces, {foam.Edges.Count} half-edges and {foam.Vertices.Count} vertices."); return(Result.Success); } else { Rhino.RhinoApp.WriteLine("Not enough faces!"); return(Result.Failure); } } catch (Exception pfE) { RhinoApp.WriteLine(pfE.Message + " Press <Esc> to continue."); foam.Hide(); return(Result.Failure); } }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { GetObject go = new GetObject(); // List of Object Types to filter List <ObjectType> enumList = new List <ObjectType> { ObjectType.Point, ObjectType.Curve, ObjectType.Extrusion, ObjectType.Surface, ObjectType.Brep, ObjectType.Mesh, ObjectType.InstanceReference, ObjectType.Light, ObjectType.ClipPlane, ObjectType.Hatch, ObjectType.Annotation, ObjectType.ClipPlane, }; string[] enumNames = Enum.GetNames(typeof(ObjectType)); var enumValues = Enum.GetValues(typeof(ObjectType)).OfType <ObjectType>().ToList(); List <OptionToggle> options = new List <OptionToggle>(); List <ObjectType> types = new List <ObjectType>(); for (int i = 0; i < enumList.Count; i++) { var value = (ObjectType)enumList[i]; var index = enumValues.IndexOf(value); if (index > -1) { var toggle = new OptionToggle(false, "Off", "On"); options.Add(toggle); types.Add(value); go.AddOptionToggle(enumNames[index], ref toggle); } } go.SetCommandPrompt("Select filter geometry types"); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; var selectedObjectTypes = new List <ObjectType>(); while (true) { GetResult res = go.GetMultiple(1, 0); // If the action is change in filter, update the filter list. if (res == GetResult.Option) { selectedObjectTypes.Clear(); go.EnablePreSelect(false, true); ObjectType objectTypes = 0; for (var i = 0; i < options.Count; i++) { var type = types[i]; if (options[i].CurrentValue) { selectedObjectTypes.Add(type); if (objectTypes == ObjectType.None) { objectTypes = type; } else { objectTypes |= type; } } } go.GeometryFilter = objectTypes; continue; } else if (res != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); continue; } break; } // Select objects that meets the filter criteria for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { if (selectedObjectTypes.Contains(rhinoObject.ObjectType)) { rhinoObject.Select(true); } else { rhinoObject.Select(false); } } } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetObject go = new GetObject(); go.SetCommandPrompt("Select meshes to Voronoi"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh; go.AddOptionToggle("OutputMesh", ref outputMeshToggle); go.AddOptionToggle("OutputLines", ref outputLinesToggle); go.AddOptionToggle("OutputPolylines", ref outputPolylinesToggle); go.AddOptionToggle("OutputNGon", ref outputNGon); for (;;) { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { continue; } if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } break; } if (go.ObjectCount < 1) { return(Result.Failure); } foreach (var obj in go.Objects()) { var rhinoMesh = obj.Mesh(); if (rhinoMesh == null || !rhinoMesh.IsValid) { continue; } var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh()); g3.DMesh3 outputMesh; List <g3.Line3d> listLines; List <g3.PolyLine3d> listPolylines; GopherUtil.VoronoiMesh(mesh, out outputMesh, out listLines, out listPolylines); var rhinoOutputMesh = GopherUtil.ConvertToRhinoMesh(outputMesh); if (outputPolylinesToggle.CurrentValue) { foreach (var p in listPolylines) { var rp = Gopher.GopherUtil.ConvertToRhinoPolyline(p); doc.Objects.AddPolyline(rp); } } if (outputLinesToggle.CurrentValue) { foreach (var l in listLines) { var rl = GopherUtil.ConvertToRhinoLine(l); doc.Objects.AddLine(rl); } } if (outputMeshToggle.CurrentValue) { if (outputNGon.CurrentValue) { // rhinoOutputMesh.Ngons.AddPlanarNgons(doc.ModelAbsoluteTolerance); doc.Objects.AddMesh(Gopher.GopherUtil.ConvertToRhinoMesh(listPolylines)); } else { doc.Objects.AddMesh(rhinoOutputMesh); } } } return(Result.Success); }
// loads or makes a polyframe and planarizes the faces // load a set of geometries // if lines => must have PolyFrame date attached // if breps and data exists => reload topology data and update from geometry // if no data exists => make topology without cells // planarize and dump to the file // add topology data if cells are present. protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetObject getObjects = new GetObject(); getObjects.SetCommandPrompt("Pick the breps or PolyFrame container to planarize "); getObjects.GeometryFilter = Rhino.DocObjects.ObjectType.Brep | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Mesh; // set up options getObjects.GroupSelect = true; OptionDouble dblOptionCollapse = new OptionDouble(0.1, true, 0.0); OptionToggle togOptionReplace = new OptionToggle(true, "Keep", "Replace"); getObjects.AddOptionDouble("PointCollapseLimit", ref dblOptionCollapse); getObjects.AddOptionToggle("ReplaceGeo", ref togOptionReplace); getObjects.AcceptNothing(false); var primal = new PFoam(); var dual = new PFoam(); while (true) { var r = getObjects.GetMultiple(1, 0); if (r == GetResult.Cancel) { return(getObjects.CommandResult()); } else if (r == GetResult.Object) { break; } } List <Guid> ids = new List <Guid>(); for (int i = 0; i < getObjects.ObjectCount; i++) { ids.Add(getObjects.Object(i).ObjectId); } try { ContainerType container = ContainerType.Edge; bool usePFTopo = false; var selGeo = getObjects.Objects().Select(x => x.Geometry()); if (selGeo.All(x => x.ObjectType == Rhino.DocObjects.ObjectType.Brep)) { if (selGeo.Any(y => y.UserDictionary.TryGetString("Primal", out string primalJson))) { Rhino.Input.RhinoGet.GetBool("PolyFrame data detected. Use topology data from there?", false, "no", "yes", ref usePFTopo); } if (usePFTopo) { //guids = LoadData.LoadPrimalDual(out primal, out dual); var brepGeo = selGeo.Cast <Brep>().ToList(); if (brepGeo.Any(x => x.Faces.Count > 1)) { container = ContainerType.CellBrep; } else { container = ContainerType.FaceBrep; } primal = LoadData.LoadFromFaces(brepGeo, out dual, true); } else { primal.ProcessBFaces(Util.DecomposeG(ids), dblOptionCollapse.CurrentValue, double.MaxValue); primal.SortPartsInFaces(); } } else if (selGeo.All(x => x.ObjectType == Rhino.DocObjects.ObjectType.Curve)) { if (selGeo.Any(y => y.UserDictionary.TryGetString("Primal", out string primalJson))) { primal = LoadData.LoadFromEdges(selGeo.Cast <Curve>().ToList(), out dual, true); //guids = LoadData.LoadPrimalDual(out primal, out dual); container = ContainerType.Edge; } else { RhinoApp.WriteLine("No PolyFrame data detected. Planarization of raw line/curve data is not supported "); return(Result.Failure); } } else if (selGeo.All(x => x.ObjectType == Rhino.DocObjects.ObjectType.Mesh)) { if (selGeo.Any(y => y.UserDictionary.TryGetString("Primal", out string primalJson))) { var meshGeos = selGeo.Cast <Mesh>().ToList(); if (meshGeos.Any(x => x.Ngons.Count > 1 || (x.Ngons.Count == 0 && x.Faces.Count > 1) || (x.Ngons.Count == 1 && x.Faces.Count > x.Ngons[0].FaceCount))) { container = ContainerType.CellMesh; } else { container = ContainerType.FaceMesh; } primal = LoadData.LoadFromMeshes(meshGeos, out dual, true); } else { RhinoApp.WriteLine("No PolyFrame data detected. Planarization of raw mesh data is not supported "); return(Result.Failure); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { try { using (var go = new GetObject()) { var wwr = 0.6; wwr = Settings.GetDouble(nameof(wwr), 0.6); var optionWWR = new OptionDouble(wwr, 0.01, 0.98); var optionSkipFaceExistingWindow = new OptionToggle(true, "No_CreateForAllFaces", "Yes"); go.SetCommandPrompt("Please select honeybee rooms for adding windows to"); go.GeometryFilter = ObjectType.Brep; go.GroupSelect = false; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; while (true) { go.ClearCommandOptions(); go.AddOptionDouble("WindowWallRatio", ref optionWWR); go.AddOptionToggle("SkipFacesWithWindows", ref optionSkipFaceExistingWindow); var res = go.GetMultiple(1, 0); if (res == Rhino.Input.GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (res != Rhino.Input.GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); continue; } break; } if (go.CommandResult() != Result.Success) { throw new ArgumentException("Failed to execute command!"); } if (go.ObjectCount == 0) { throw new ArgumentException("No object is selected!"); } //get option values Settings.SetDouble(nameof(wwr), optionWWR.CurrentValue); var ifSkipFaceWithWindow = optionSkipFaceExistingWindow.CurrentValue; //all selected room geometries var solidBreps = go.Objects().Where(_ => _.Brep() != null).Where(_ => _.Brep().IsSolid); var rooms = solidBreps.Where(_ => _.IsRoom()).ToList(); if (solidBreps.Count() != rooms.Count()) { doc.Objects.UnselectAll(); var nonRooms = solidBreps.Where(_ => !_.Brep().IsRoom()); foreach (var item in nonRooms) { doc.Objects.Select(item, true, true); } doc.Views.Redraw(); Rhino.UI.Dialogs.ShowMessage("These are not Honeybee rooms, please use MassToRoom to convert them first!", "Honeybee Rhino Plugin"); return(Result.Failure); } //Add Windows AddApertureByWWR(doc, rooms, optionWWR.CurrentValue, ifSkipFaceWithWindow); doc.Views.Redraw(); return(Result.Success); } } catch (Exception e) { RhinoApp.WriteLine($"ERROR: {e.Message}"); return(Result.Failure); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { ActiveDoc = doc; const ObjectType geometryFilter = ObjectType.Curve | ObjectType.Surface; OptionToggle toggle = new OptionToggle(true, "Remove", "Apply"); GetObject go = new GetObject(); go.SetCommandPrompt("Select curves or surfaces"); go.GeometryFilter = geometryFilter; go.AddOptionToggle("BuiltElements", ref toggle); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool hasPreselected = 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) { hasPreselected = true; go.EnablePreSelect(false, true); continue; } break; } if (hasPreselected) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // Currently, leave everything selected post command. for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(true); } } doc.Views.Redraw(); } List <RhinoObject> commandObjs = go.Objects().Select(o => o.Object()).ToList(); if (toggle.CurrentValue == true) { ApplySchemas(commandObjs); } else { DeleteSchemas(commandObjs); } return(Result.Success); }