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) { 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) { 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); } }