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 Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc) { Rhino.DocObjects.ObjRef rail_ref; var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref); if (rc != Rhino.Commands.Result.Success) { return(rc); } var rail_crv = rail_ref.Curve(); if (rail_crv == null) { return(Rhino.Commands.Result.Failure); } var gx = new Rhino.Input.Custom.GetObject(); gx.SetCommandPrompt("Select cross section curves"); gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gx.EnablePreSelect(false, true); gx.GetMultiple(1, 0); if (gx.CommandResult() != Rhino.Commands.Result.Success) { return(gx.CommandResult()); } var cross_sections = new List <Rhino.Geometry.Curve>(); for (int i = 0; i < gx.ObjectCount; i++) { var crv = gx.Object(i).Curve(); if (crv != null) { cross_sections.Add(crv); } } if (cross_sections.Count < 1) { return(Rhino.Commands.Result.Failure); } var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians; sweep.ClosedSweep = false; sweep.SweepTolerance = doc.ModelAbsoluteTolerance; sweep.SetToRoadlikeTop(); var breps = sweep.PerformSweep(rail_crv, cross_sections); for (int i = 0; i < breps.Length; i++) { doc.Objects.AddBrep(breps[i]); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to flow", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject(); go0.SetCommandPrompt("Source curve"); go0.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go0.SubObjectSelect = false; go0.EnablePreSelect(false, true); go0.DeselectAllBeforePostSelect = false; go0.Get(); if (go0.CommandResult() != Rhino.Commands.Result.Success) { return(go0.CommandResult()); } Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0); Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject(); go1.SetCommandPrompt("Source curve"); go1.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go1.SubObjectSelect = false; go1.EnablePreSelect(false, true); go1.DeselectAllBeforePostSelect = false; go1.Get(); if (go1.CommandResult() != Rhino.Commands.Result.Success) { return(go1.CommandResult()); } Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0); Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result Flow(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to flow", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) return rc; Rhino.Input.Custom.GetObject go0 = new Rhino.Input.Custom.GetObject(); go0.SetCommandPrompt("Source curve"); go0.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go0.SubObjectSelect = false; go0.EnablePreSelect(false, true); go0.DeselectAllBeforePostSelect = false; go0.Get(); if (go0.CommandResult() != Rhino.Commands.Result.Success) return go0.CommandResult(); Rhino.DocObjects.ObjRef crv0_ref = go0.Object(0); Rhino.Input.Custom.GetObject go1 = new Rhino.Input.Custom.GetObject(); go1.SetCommandPrompt("Source curve"); go1.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go1.SubObjectSelect = false; go1.EnablePreSelect(false, true); go1.DeselectAllBeforePostSelect = false; go1.Get(); if (go1.CommandResult() != Rhino.Commands.Result.Success) return go1.CommandResult(); Rhino.DocObjects.ObjRef crv1_ref = go1.Object(0); Rhino.Geometry.Morphs.FlowSpaceMorph morph = new Rhino.Geometry.Morphs.FlowSpaceMorph(crv0_ref.Curve(), crv1_ref.Curve(), false); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return Rhino.Commands.Result.Success; }
public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to splop", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Surface to splop on"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go.SubObjectSelect = false; go.EnablePreSelect(false, true); go.DeselectAllBeforePostSelect = false; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } Rhino.DocObjects.ObjRef srfref = go.Object(0); double u, v; srfref.SurfaceParameter(out u, out v); Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u, v); Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result Sweep1(Rhino.RhinoDoc doc) { Rhino.DocObjects.ObjRef rail_ref; var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref); if(rc!=Rhino.Commands.Result.Success) return rc; var rail_crv = rail_ref.Curve(); if( rail_crv==null ) return Rhino.Commands.Result.Failure; var gx = new Rhino.Input.Custom.GetObject(); gx.SetCommandPrompt("Select cross section curves"); gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gx.EnablePreSelect(false, true); gx.GetMultiple(1,0); if( gx.CommandResult() != Rhino.Commands.Result.Success ) return gx.CommandResult(); var cross_sections = new List<Rhino.Geometry.Curve>(); for( int i=0; i<gx.ObjectCount; i++ ) { var crv = gx.Object(i).Curve(); if( crv!= null) cross_sections.Add(crv); } if( cross_sections.Count<1 ) return Rhino.Commands.Result.Failure; var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians; sweep.ClosedSweep = false; sweep.SweepTolerance = doc.ModelAbsoluteTolerance; sweep.SetToRoadlikeTop(); var breps = sweep.PerformSweep(rail_crv, cross_sections); for( int i=0; i<breps.Length; i++ ) doc.Objects.AddBrep(breps[i]); doc.Views.Redraw(); return Rhino.Commands.Result.Success; }
public static Rhino.Commands.Result Splop(Rhino.RhinoDoc doc) { ObjectType filter = SpaceMorphObjectFilter(); Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to splop", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) return rc; Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Surface to splop on"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go.SubObjectSelect = false; go.EnablePreSelect(false, true); go.DeselectAllBeforePostSelect = false; go.Get(); if (go.CommandResult() != Rhino.Commands.Result.Success) return go.CommandResult(); Rhino.DocObjects.ObjRef srfref = go.Object(0); double u, v; srfref.SurfaceParameter(out u, out v); Rhino.Geometry.Point2d uv = new Rhino.Geometry.Point2d(u,v); Rhino.Geometry.Morphs.SplopSpaceMorph morph = new Rhino.Geometry.Morphs.SplopSpaceMorph(plane, srfref.Surface(), uv); Rhino.Geometry.GeometryBase geom = objref.Geometry().Duplicate(); if (morph.Morph(geom)) { doc.Objects.Add(geom); doc.Views.Redraw(); } return Rhino.Commands.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); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //select the cross-section faces var gc = new Rhino.Input.Custom.GetObject(); gc.SetCommandPrompt("Select the surfaces which form the cross-section of the beam."); gc.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gc.EnablePreSelect(false, true); gc.GetMultiple(1, 1); if (gc.CommandResult() != Rhino.Commands.Result.Success) { return(gc.CommandResult()); } var face = gc.Object(0).Face(); //for each cross-section, get the base-surface curve var gv = new Rhino.Input.Custom.GetObject(); gv.SetCommandPrompt("Select the base_curve."); gv.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gv.EnablePreSelect(false, true); gv.GetMultiple(1, 1); if (gv.CommandResult() != Rhino.Commands.Result.Success) { return(gv.CommandResult()); } var base_curve = gv.Object(0).Curve(); //List of all the sub section List <Brep> sub_sections = new List <Brep>(); for (int i = 0; i < 10; i++) { //offset the base to form a closed loop var curves = base_curve.OffsetOnSurface(face, 0.1, doc.ModelAbsoluteTolerance); if (curves.Length > 1) { Rhino.RhinoApp.WriteLine("More than one offset"); return(Result.Failure); } var offset_curve = curves[0]; //connect the curves in a closed loop LineCurve edge1 = new LineCurve(base_curve.PointAtStart, offset_curve.PointAtStart); LineCurve edge2 = new LineCurve(offset_curve.PointAtEnd, base_curve.PointAtEnd); List <Curve> prejoin = new List <Curve>(); prejoin.Add(edge1); prejoin.Add(edge2); prejoin.Add(base_curve); prejoin.Add(offset_curve); var loops = Curve.JoinCurves(prejoin, doc.ModelAbsoluteTolerance); if (loops.Length > 1) { Rhino.RhinoApp.WriteLine("More than one joined loops"); return(Result.Failure); } var loop = loops[0]; var breps = Rhino.Geometry.Brep.CreatePlanarBreps(loop); if (breps.Length > 1) { Rhino.RhinoApp.WriteLine("More than one joined loops"); return(Result.Failure); } sub_sections.Add(breps[0]); doc.Objects.AddBrep(breps[0]); doc.Views.Redraw(); base_curve = offset_curve; } //compute moment of inertia var area_properties1 = Rhino.Geometry.AreaMassProperties.Compute(sub_sections); var area_properties2 = Rhino.Geometry.AreaMassProperties.Compute(face); //check for the difference Rhino.RhinoApp.WriteLine("Area {0}", area_properties1.Area); Rhino.RhinoApp.WriteLine("Difference in Area {0}", area_properties1.Area - area_properties2.Area); Rhino.RhinoApp.WriteLine("Moment X: {0}; Y: {1}; Z: {2} in WCS ", area_properties1.WorldCoordinatesMomentsOfInertia.X, area_properties1.WorldCoordinatesMomentsOfInertia.Y, area_properties1.WorldCoordinatesMomentsOfInertia.Z); Rhino.RhinoApp.WriteLine("Difference in Moment X: {0}; Y: {1}; Z: {2} in WCS", area_properties1.WorldCoordinatesMomentsOfInertia.X - area_properties2.WorldCoordinatesMomentsOfInertia.X, area_properties1.WorldCoordinatesMomentsOfInertia.Y - area_properties2.WorldCoordinatesMomentsOfInertia.Y, area_properties1.WorldCoordinatesMomentsOfInertia.Z - area_properties2.WorldCoordinatesMomentsOfInertia.Z); //display the centroids doc.Objects.AddPoint(area_properties1.Centroid); doc.Objects.AddPoint(area_properties2.Centroid); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //select the cross-section faces var gb = new Rhino.Input.Custom.GetObject(); gb.SetCommandPrompt("Select the surfaces which form the cross-section of the beam."); gb.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; gb.EnablePreSelect(false, true); gb.GetMultiple(1, 0); if (gb.CommandResult() != Rhino.Commands.Result.Success) { return(gb.CommandResult()); } List <BrepFace> cross_section = new List <BrepFace>(); for (int i = 0; i < gb.ObjectCount; i++) { var face = gb.Object(i).Face(); if (face != null) { cross_section.Add(face); } } //select the rail Rhino.DocObjects.ObjRef rail_ref; var rc = RhinoGet.GetOneObject("Select rail curve", false, Rhino.DocObjects.ObjectType.Curve, out rail_ref); if (rc != Rhino.Commands.Result.Success) { return(rc); } var rail_crv = rail_ref.Curve(); if (rail_crv == null) { return(Rhino.Commands.Result.Failure); } var gx = new Rhino.Input.Custom.GetObject(); gx.SetCommandPrompt("Select cross section curves"); gx.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gx.EnablePreSelect(false, true); gx.GetMultiple(1, 0); if (gx.CommandResult() != Rhino.Commands.Result.Success) { return(gx.CommandResult()); } var cross_sections = new List <Rhino.Geometry.Curve>(); for (int i = 0; i < gx.ObjectCount; i++) { var crv = gx.Object(i).Curve(); if (crv != null) { cross_sections.Add(crv); } } if (cross_sections.Count < 1) { return(Rhino.Commands.Result.Failure); } var sweep = new Rhino.Geometry.SweepOneRail(); sweep.AngleToleranceRadians = doc.ModelAngleToleranceRadians; sweep.ClosedSweep = false; sweep.SweepTolerance = doc.ModelAbsoluteTolerance; //sweep.SetToRoadlikeTop(); var breps = sweep.PerformSweep(rail_crv, cross_sections); for (int i = 0; i < breps.Length; i++) { doc.Objects.AddBrep(breps[i]); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { List <Rhino.Geometry.Mesh> meshes = new List <Rhino.Geometry.Mesh>(); try { string ogre_bin = System.Environment.GetEnvironmentVariable("OGRE_HOME"); #if DEBUG ogre_bin += @"\bin\Debug"; #else ogre_bin += @"\bin\Release"; #endif string path = System.Environment.GetEnvironmentVariable("PATH"); System.Environment.SetEnvironmentVariable("PATH", path + ";" + ogre_bin, EnvironmentVariableTarget.Process); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); OptionToggle export_as_xml = new OptionToggle(false, "No", "Yes"); go.AddOptionToggle("export_as_xml", ref export_as_xml); 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 (; ;) { 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.Object) { RhinoLogger.Info("Canceled."); return(Rhino.Commands.Result.Cancel); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } SaveFileDialog sv = new SaveFileDialog(); if (!export_as_xml.CurrentValue) { sv.Filter = "Mesh files (*.mesh)|*.mesh"; sv.DefaultExt = "mesh"; } else { sv.Filter = "XML files (*.xml)|*.xml"; sv.DefaultExt = "xml"; } sv.Title = "Select File to Export :"; if (sv.ShowDialog() != System.Windows.Forms.DialogResult.OK) { RhinoLogger.Info("Canceled."); return(Result.Cancel); } if (bHavePreselectedObjects) { // Normally when command finishes, pre-selected objects will remain // selected, when and post-selected objects will be unselected. // With this sample, it is possible to have a combination of // pre-selected and post-selected objects. To make sure everything // "looks the same", unselect everything before finishing the command. for (int i = 0; i < go.ObjectCount; i++) { Rhino.DocObjects.RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } int objectCount = go.ObjectCount; Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount); for (int i = 0; i < objectCount; i++) { var objref = go.Object(i); if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Mesh) { meshes.Add(objref.Mesh()); } else if (objref.Geometry().ObjectType == Rhino.DocObjects.ObjectType.Brep) { var ms = CheckOrCreateMesh(objref.Brep(), RhinoDoc.ActiveDoc.GetMeshingParameters(MeshingParameterStyle.Custom)); meshes.AddRange(ms); } else { RhinoLogger.ErrorFormat("selection is unexpected ObjectType : {0}", objref.Geometry().ObjectType); return(Result.Failure); } } var exporter = new ExportToOgreMesh(); var exp_path = exporter.Export(sv.FileName, meshes); if (!export_as_xml.CurrentValue) { exporter.ConvertXmlToMesh(exp_path); } } catch (Exception e) { RhinoLogger.Fatal(e); return(Result.Failure); } return(Result.Success); }