public static List <Guid> Guids(ObjectType filter) { GetObject go; while (true) { go = new GetObject(); go.AcceptNothing(true); go.AcceptEnterWhenDone(true); go.SetCommandPrompt("请选择一个或多个,之后回车确认"); go.GeometryFilter = filter; if (go.GetMultiple(1, 0) != GetResult.Object) { return(null); } List <Guid> ghCurveList1 = new List <Guid>(); Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(obj.ObjectId)); if (ghCurveList1.Count == 0) { return(null); } return(ghCurveList1); } }
public static List <Curve> Curves() { GetObject go; while (true) { go = new GetObject(); go.AcceptNothing(true); go.AcceptEnterWhenDone(true); go.SetCommandPrompt("请选择一条或多条曲线,之后回车或者右键确认"); go.GeometryFilter = ObjectType.Curve | ObjectType.EdgeFilter; if (go.GetMultiple(1, 0) != GetResult.Object) { return(null); } List <Curve> ghCurveList1 = new List <Curve>(); Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(obj.Curve())); if (ghCurveList1.Count == 0) { return(null); } return(ghCurveList1); } }
public static List <GH_Point> PickPoint() { GetObject go; while (true) { go = new GetObject(); go.AcceptNothing(true); go.AcceptEnterWhenDone(true); go.SetCommandPrompt("请选择一个或多个,之后回车确认"); go.GeometryFilter = ObjectType.Point; if (go.GetMultiple(1, 0) != GetResult.Object) { return(null); } List <GH_Point> ghCurveList1 = new List <GH_Point>(); Array.ForEach(go.Objects(), (ObjRef obj) => ghCurveList1.Add(new GH_Point(obj.Point().Location))); if (ghCurveList1.Count == 0) { return(null); } return(ghCurveList1); } }
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); } } } }
public static List <T> Pick <T>(ObjectType filter, string message) { GetObject go; while (true) { go = new GetObject(); go.AcceptNothing(true); go.AcceptEnterWhenDone(true); go.SetCommandPrompt(message); go.GeometryFilter = filter; if (go.GetMultiple(1, 0) != GetResult.Object) { return(null); } List <T> list = new List <T>(); Array.ForEach(go.Objects(), (ObjRef obj) => { dynamic geo; if (typeof(T).Name == "GH_Point") { geo = obj.Point().Location; } else if (typeof(T).Name == "GH_Curve") { geo = obj.Curve(); } else { geo = null; } if (geo != null) { list.Add(geo); } }); if (list.Count == 0) { return(null); } return(list); } }
public static Point3d Point() { GetObject go; while (true) { go = new GetObject(); go.AcceptNothing(true); go.AcceptEnterWhenDone(true); go.SetCommandPrompt("请选择一条点物件,之后回车或者右键确认"); go.GeometryFilter = ObjectType.Point; if (go.Get() != GetResult.Object) { return(Point3d.Unset); } var obj = go.Object(0); return(obj.Point().Location); } }
public static Guid Guid(ObjectType filter) { GetObject go; while (true) { go = new GetObject(); go.AcceptNothing(true); go.AcceptEnterWhenDone(true); go.SetCommandPrompt("请选择一个物件,之后回车确认"); go.GeometryFilter = filter; if (go.Get() != GetResult.Object) { return(System.Guid.Empty); } var obj = go.Object(0); return(obj.ObjectId); } }
public static Curve Curve() { GetObject go; while (true) { go = new GetObject(); go.AcceptNothing(true); go.AcceptEnterWhenDone(true); go.SetCommandPrompt("请选择一条曲线,之后回车或者右键确认"); go.GeometryFilter = ObjectType.Curve | ObjectType.EdgeFilter; if (go.Get() != GetResult.Object) { return(null); } var obj = go.Object(0); var crv = obj.Curve(); return(crv); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetObject go; go = new GetObject(); go.AcceptNothing(true); go.AcceptEnterWhenDone(true); go.SetCommandPrompt("请选择边界"); go.GeometryFilter = ObjectType.Curve; if (go.Get() != GetResult.Object) { return(Result.Failure); } Curve boundCrv = go.Object(0).Curve(); if (!boundCrv.IsPlanar() || !boundCrv.IsPolyline() || !boundCrv.IsClosed) { return(Result.Failure); } boundCrv.GetBoundingBox(Plane.WorldXY, out Box bound); var dialog = new SelectFolderDialog() { Title = "保存位置" }; DialogResult res = dialog.ShowDialog(Rhino.UI.RhinoEtoApp.MainWindow); if (res == DialogResult.Ok) { try { Dictionary <string, string> pathMap = new Dictionary <string, string>(); foreach (var layer in doc.Layers) { var objects = doc.Objects.FindByLayer(layer); if (!layer.IsVisible || !layer.IsValid || objects.Length == 0) { continue; } string name = layer.FullPath.Replace(Layer.PathSeparator, "$$"); string realPath = IOPath.Combine(dialog.Directory, name + ".eps"); string tmpPath = IOPath.Combine(IOPath.GetTempPath(), layer.Id.ToString()); var eps = new EncapsulatedPostScript(bound); var objs = SelectAllObjectsInBound(bound, objects); if (objs.Count == 0) { continue; } eps.SaveEPS(objs, tmpPath); pathMap.Add(tmpPath, realPath); } if (pathMap.Count == 0) { return(Result.Cancel); } foreach (KeyValuePair <string, string> item in pathMap) { System.IO.File.Move(item.Key, item.Value); RhinoApp.WriteLine($"已写入, {item.Value}"); } System.Diagnostics.Process.Start(dialog.Directory); } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); } finally { doc.Objects.UnselectAll(); doc.Views.Redraw(); } } 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) { // 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); } }
// 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); } }