protected override Result RunCommand(RhinoDoc doc, RunMode mode) { 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; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { 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); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; int integer1 = 300; int integer2 = 300; Rhino.Input.Custom.OptionInteger optionInteger1 = new Rhino.Input.Custom.OptionInteger(integer1, 200, 900); Rhino.Input.Custom.OptionInteger optionInteger2 = new Rhino.Input.Custom.OptionInteger(integer2, 200, 900); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GeometryFilter = geometryFilter; go.AddOptionInteger("Option1", ref optionInteger1); go.AddOptionInteger("Option2", ref optionInteger2); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (; ;) { 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) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } if (bHavePreselectedObjects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets 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; integer1 = optionInteger1.CurrentValue; integer2 = optionInteger2.CurrentValue; RhinoApp.WriteLine("Select object count = {0}", objectCount); RhinoApp.WriteLine("Value of integer1 = {0}", integer1); RhinoApp.WriteLine("Value of integer2 = {0}", integer2); return(Result.Success); }
public static GeometryLarge CreateGeometry(MaterialType mType, string mName) { RhinoDoc doc = RhinoDoc.ActiveDoc; //Allow user to pick multiple objects const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Curve; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject() { GeometryFilter = geometryFilter, GroupSelect = true, SubObjectSelect = false, DeselectAllBeforePostSelect = false }; go.SetCommandPrompt("Pick one or two closed curves."); 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(); } ObjRef[] objs = go.Objects(); List <Curve> selectedCurves = new List <Curve>(); foreach (ObjRef objRef in objs) { if (objRef.Curve() == null) { RhinoApp.WriteLine("One of the selected objects was invalid."); continue; } else if (!objRef.Curve().IsClosed) { RhinoApp.WriteLine("One of the selected curves was not closed."); continue; } selectedCurves.Add(objRef.Curve()); } GeometryLarge larg; //if the curve is not closed do nothing switch (selectedCurves.Count) { case 0: Rhino.RhinoApp.WriteLine("No valid geometries was found."); return(null); case 1: larg = DrawAndSaveUserAttr(Brep.CreatePlanarBreps(selectedCurves)[0], doc, mType, mName); break; case 2: Brep brep1 = Brep.CreatePlanarBreps(new[] { selectedCurves[0] })[0]; Brep brep2 = Brep.CreatePlanarBreps(new[] { selectedCurves[1] })[0]; double area = Brep.CreateBooleanUnion(new[] { brep1, brep2 }, 0.001)[0].GetArea(); double brep1Area = brep1.GetArea(); double brep2Area = brep2.GetArea(); if (area > 0.999 * brep1Area && area < 1.001 * brep1Area) { Brep brep = Brep.CreateBooleanDifference(brep1, brep2, doc.ModelAbsoluteTolerance)[0]; larg = DrawAndSaveUserAttr(brep, doc, mType, mName); break; } else if (area > 0.999 * brep2Area && area < 1.001 * brep2Area) { Brep brep = Brep.CreateBooleanDifference(brep1, brep2, doc.ModelAbsoluteTolerance)[0]; larg = DrawAndSaveUserAttr(brep, doc, mType, mName); break; } else { RhinoApp.WriteLine("The curves were not inside one another."); return(null); } default: return(null); } foreach (ObjRef objRef in objs) { doc.Objects.Delete(objRef, false); } return(larg); }
///<summary> This gets called when when the user runs this command.</summary> protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { SourceConduit m_source_conduit = SourceConduit.Instance; Rhino.Input.Custom.GetObject GO = new Rhino.Input.Custom.GetObject(); GO.SetCommandPrompt("Select source curve..."); GO.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; GO.AddOption("TrafficWelsh"); GO.AddOption("TrafficFHWA"); GO.AddOption("AircraftANCON"); GO.AddOption("Custom"); //GO.AddOptionList("SourceType", new List<string>() { "TrafficWelshStandard", "TrafficFHWA Standard", "Custom" }, 2); GO.GroupSelect = false; GO.SubObjectSelect = false; GO.EnableClearObjectsOnEntry(false); GO.EnableUnselectObjectsOnExit(false); GO.DeselectAllBeforePostSelect = false; int pavement = 0; double SPLW = 0; double[] SWL = new double[] { 120, 120, 120, 120, 120, 120, 120, 120 }; double velocity = 83; double delta = 45; double choice = 0; for (; ; ) { Rhino.Input.GetResult GR = GO.GetMultiple(1, 1); int type = GO.OptionIndex(); if (GR == Rhino.Input.GetResult.Option) { choice = (int)type; //type = GO.Option().EnglishName; if (type == 1)//"Traffic (Welsh Standard)") { Rhino.Input.RhinoGet.GetNumber("Input basis road sound pressure level at 1 m from street...", false, ref SPLW); SPLW += 8; } else if (type == 2)//"Traffic (FHWA Standard)") { ///Described at: ///http://www.fhwa.dot.gov/environment/noise/traffic_noise_model/old_versions/tnm_version_10/tech_manual/tnm03.cfm#tnma2 double s = 0; //int i = 0; Rhino.Input.RhinoGet.GetNumber("Enter the speed of traffic on this road (in kph)...", false, ref s); ///Pavement Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption(); GOpt.SetCommandPrompt("Pavement type..."); GOpt.AddOption("Average_DGAC_PCC)"); GOpt.AddOption("DGAC_Asphalt"); GOpt.AddOption("PCC_Concrete"); GOpt.AddOption("OGAC_OpenGradedAsphalt"); GOpt.AcceptNothing(false); GOpt.Get(); pavement = GOpt.OptionIndex(); ///Vehicle tallies double[] Veh = new double[5] { 0, 0, 0, 0, 0 }; Rhino.Input.RhinoGet.GetNumber("Enter the number of automobiles per hour...", false, ref Veh[0]); Rhino.Input.RhinoGet.GetNumber("Enter the number of medium trucks per hour...", false, ref Veh[1]); Rhino.Input.RhinoGet.GetNumber("Enter the number of heavy trucks per hour...", false, ref Veh[2]); Rhino.Input.RhinoGet.GetNumber("Enter the number of buses per hour...", false, ref Veh[3]); Rhino.Input.RhinoGet.GetNumber("Enter the number of motorcycles per hour...", false, ref Veh[4]); bool throttle = false; int t = 0; Rhino.Input.RhinoGet.GetBool("Full throttle?", false, "Yes", "No", ref throttle); t = (throttle) ? 1 : 0; double root2 = Math.Sqrt(2); double vtot = 0; double[] Es = new double[8] { 0, 0, 0, 0, 0, 0, 0, 0 }; for (int v = 0; v < 5; v++) { double A = FHWATraffic[v][pavement][t][0]; double B = FHWATraffic[v][pavement][t][1]; double C = FHWATraffic[v][pavement][t][2]; double D1 = FHWATraffic[v][pavement][t][3]; double D2 = FHWATraffic[v][pavement][t][4]; double E1 = FHWATraffic[v][pavement][t][5]; double E2 = FHWATraffic[v][pavement][t][6]; double F1 = FHWATraffic[v][pavement][t][7]; double F2 = FHWATraffic[v][pavement][t][8]; double G1 = FHWATraffic[v][pavement][t][9]; double G2 = FHWATraffic[v][pavement][t][10]; double H1 = FHWATraffic[v][pavement][t][11]; double H2 = FHWATraffic[v][pavement][t][12]; double I1 = FHWATraffic[v][pavement][t][13]; double I2 = FHWATraffic[v][pavement][t][14]; double J1 = FHWATraffic[v][pavement][t][15]; double J2 = FHWATraffic[v][pavement][t][16]; vtot += Veh[v]; for (int oct = 0; oct < 8; oct++) { double f = 62.5 * Math.Pow(2, oct); double[] freq = new double[3] { f / root2, f, f * root2 }; for (int oct3 = 0; oct3 < 3; oct3++) { double Ea = Math.Pow(0.6214 * s, A / 10) * Math.Pow(10, B / 10) + Math.Pow(10, C / 10); double logf = Math.Log10(freq[oct3]); double Ls = 10 * Math.Log10(Ea) + (D1 + 0.6214 * D2 * s) + (E1 + 0.6214 * E2 * s) * logf + (F1 + 0.6214 * F2 * s) * logf * logf + (G1 + 0.6214 * G2 * s) * logf * logf * logf + (H1 + 0.6214 * H2 * s) * logf * logf * logf * logf + (I1 + 0.6214 * I2 * s) * logf * logf * logf * logf * logf + (J1 + 0.6214 * J2 * s) * logf * logf * logf * logf * logf * logf; Es[oct] += 0.0476 * Math.Pow(10, Ls / 10) * Veh[v] / s; } } } double[] Awt = new double[8] { -26, -16, -9, -3, 0, 1.2, 1, -1 }; double dmod = 10 * Math.Log10(1 / (Utilities.Numerics.PiX2 * 15)); for (int oct = 0; oct < 8; oct++) { SWL[oct] = 10 * Math.Log10(Es[oct]) - Awt[oct] - dmod;// } } else if (type == 3)//"Aircraft (ANCON-derived)") { Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption(); GOpt.SetCommandPrompt("Takeoff or Landing?"); GOpt.AddOption("Takeoff"); GOpt.AddOption("Landing"); GOpt.AddOption("Both"); GOpt.AcceptNothing(false); GOpt.Get(); int TL_Choice = GOpt.OptionIndex(); double SWLA = 150; Rhino.Input.RhinoGet.GetNumber("What is the broadband sound power of the aircraft (in dBA)?", false, ref SWLA); Rhino.Input.RhinoGet.GetNumber("What is the maximum velocity of the aircraft in m/s?", false, ref velocity); Rhino.Input.RhinoGet.GetNumber("What is the slant angle for this aircraft?", false, ref delta); double[][] Aircraft_Normalization = new double[3][] { //new double[8]{ -12, -10.5, -12, -15, -20, -27, -40, -44}, //new double[8]{-11, -13, -12, -13.5, -18, -21, -25, -35}, //new double[8]{-11, -10.5, -12, -13.5, -18, -21, -25, -35} new double[8] { 6.191472203, 7.691472203, 6.191472203, 3.191472203, -1.808527797, -8.808527797,-21.8085278, -25.8085278}, new double[8] { 5.6783811710, 3.6783811710, 4.678381171, 3.178381171, -1.321618829, -4.321618829, -8.321618829, -18.32161883}, new double[8] { 5.678381171, 6.178381171, 4.678381171, 3.178381171, -1.321618829, -4.321618829, -8.321618829, -18.32161883} }; for (int oct = 0; oct < 8; oct++) { SWL[oct] = SWLA + Aircraft_Normalization[TL_Choice-1][oct];// } } // continue; // //return Result.Success; //} } else if (GR == Rhino.Input.GetResult.Object) { for (int i = 0; i < GO.ObjectCount; i++) { Rhino.DocObjects.ObjRef obj = GO.Object(i); Rhino.DocObjects.RhinoObject rhObj = doc.Objects.Find(obj.ObjectId); rhObj.Attributes.Name = "Acoustical Source"; if (choice == 1)//"Traffic (Welsh Standard)") { rhObj.Geometry.SetUserString("SourceType", "Traffic (Welsh)"); for (int oct = 0; oct < 8; oct++) SWL[oct] = SPLW + WelshTraffic[oct]; } else if (choice == 2)//"Traffic (FWHA Standard)") { rhObj.Geometry.SetUserString("SourceType", "Traffic (FHWA)"); } else if (choice == 3)//"Aircraft (ANCON-derived)") { rhObj.Geometry.SetUserString("SourceType", "Aircraft (ANCON derived)"); rhObj.Geometry.SetUserString("Velocity", velocity.ToString()); rhObj.Geometry.SetUserString("delta", delta.ToString()); } else { Rhino.Input.RhinoGet.GetNumber("62.5 Hz. Sound Power Level", true, ref SWL[0]); Rhino.Input.RhinoGet.GetNumber("125 Hz. Sound Power Level", true, ref SWL[1]); Rhino.Input.RhinoGet.GetNumber("250 Hz. Sound Power Level", true, ref SWL[2]); Rhino.Input.RhinoGet.GetNumber("500 Hz. Sound Power Level", true, ref SWL[3]); Rhino.Input.RhinoGet.GetNumber("1000 Hz. Sound Power Level", true, ref SWL[4]); Rhino.Input.RhinoGet.GetNumber("2000 Hz. Sound Power Level", true, ref SWL[5]); Rhino.Input.RhinoGet.GetNumber("4000 Hz. Sound Power Level", true, ref SWL[6]); Rhino.Input.RhinoGet.GetNumber("8000 Hz. Sound Power Level", true, ref SWL[7]); } rhObj.Geometry.SetUserString("SWL", Utilities.PachTools.EncodeSourcePower(SWL)); rhObj.Geometry.SetUserString("Phase", "0;0;0;0;0;0;0;0"); doc.Objects.ModifyAttributes(rhObj, rhObj.Attributes, true); m_source_conduit.SetSource(rhObj); } doc.Views.Redraw(); return Result.Success; } else return Result.Cancel; } }
///<summary> This gets called when when the user runs this command.</summary> protected override Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { SourceConduit m_source_conduit = SourceConduit.Instance; //Rhino.DocObjects.ObjRef location; string type = "custom"; Rhino.Input.Custom.GetObject GO = new Rhino.Input.Custom.GetObject(); GO.SetCommandPrompt("Select source surface..."); GO.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; GO.AddOption("Crowd"); GO.GroupSelect = false; GO.SubObjectSelect = false; GO.EnableClearObjectsOnEntry(false); GO.EnableUnselectObjectsOnExit(false); GO.DeselectAllBeforePostSelect = false; int Men = 100, Women = 100, Kids = 100, effort = 0; do { Rhino.Input.GetResult GR = GO.Get(); if (GR == Rhino.Input.GetResult.Option) { type = GO.Option().EnglishName; if (type == "Crowd") { Rhino.Input.RhinoGet.GetInteger("Number of Men in Crowd...", true, ref Men); Rhino.Input.RhinoGet.GetInteger("Number of Women in Crowd...", true, ref Women); Rhino.Input.RhinoGet.GetInteger("Number of Children in Crowd...", true, ref Kids); Rhino.Input.Custom.GetOption GOpt = new Rhino.Input.Custom.GetOption(); GOpt.SetCommandPrompt("Speech Activity"); GOpt.AddOption("SoftOrWhispered"); GOpt.AddOption("Conversation"); GOpt.AddOption("CompetingConversation"); GOpt.AddOption("Singing"); GOpt.AddOption("AllShouting"); GOpt.AcceptNothing(false); GOpt.Get(); effort = GOpt.OptionIndex() - 1; } continue; } else if (GR == Rhino.Input.GetResult.Object) { for (int i = 0; i < GO.ObjectCount; i++) { Rhino.DocObjects.ObjRef obj = GO.Object(i); Rhino.DocObjects.RhinoObject rhObj = doc.Objects.Find(obj.ObjectId); double Area = (rhObj.Geometry as Rhino.Geometry.Brep).GetArea(); rhObj.Attributes.Name = "Acoustical Source"; rhObj.Geometry.SetUserString("SourceType", ""); double[] SPL = new double[] { 120, 120, 120, 120, 120, 120, 120, 120 }; if (type == "Crowd") { //double mod = (effort < 3) ? .5 : 1; //Correct for tightly packed spaces, and competing speech. //if (Area / (Men + Women + Kids) < 3.0f) //{ // //In overcrowded scenarios, vocal effort escalates as such: // //whispering becomes conversation. // //conversation becomes competing conversation. // //competing conversation becomes shouting. // //Singing stays singing... I'm pretty sure experienced singers wouldn't start shouting... // if (effort < 2) effort++; // else effort = 4; //} for (int oct = 0; oct < 8; oct++) { double Power = Men * Math.Pow(10, Males[effort][oct] / 10) + Women * Math.Pow(10, Females[effort][oct] / 10) + Kids * Math.Pow(10, Children[effort][oct] / 10); //Power /= (Area); SPL[oct] = 10 * Math.Log10(Power) + 11; } } else { Rhino.Input.RhinoGet.GetNumber("62.5 Hz. Sound Power Level", true, ref SPL[0]); Rhino.Input.RhinoGet.GetNumber("125 Hz. Sound Power Level", true, ref SPL[1]); Rhino.Input.RhinoGet.GetNumber("250 Hz. Sound Power Level", true, ref SPL[2]); Rhino.Input.RhinoGet.GetNumber("500 Hz. Sound Power Level", true, ref SPL[3]); Rhino.Input.RhinoGet.GetNumber("1000 Hz. Sound Power Level", true, ref SPL[4]); Rhino.Input.RhinoGet.GetNumber("2000 Hz. Sound Power Level", true, ref SPL[5]); Rhino.Input.RhinoGet.GetNumber("4000 Hz. Sound Power Level", true, ref SPL[6]); Rhino.Input.RhinoGet.GetNumber("8000 Hz. Sound Power Level", true, ref SPL[7]); } rhObj.Geometry.SetUserString("SWL", Utilities.PachTools.EncodeSourcePower(SPL)); rhObj.Geometry.SetUserString("Phase", "0;0;0;0;0;0;0;0"); doc.Objects.ModifyAttributes(rhObj, rhObj.Attributes, true); m_source_conduit.SetSource(rhObj); } doc.Views.Redraw(); return Result.Success; } else return Result.Cancel; } while (true); }
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(ProjectPlugIn.Instance.CurrentBeam) { Material = new SteelMaterial("B500B", SteelType.Reinforcement, ProjectPlugIn.Instance.CurrentBeam), Centroid = 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); }
public Boolean createDimensions(List <Guid> guidList) { doc = RhinoDoc.ActiveDoc; go = new Rhino.Input.Custom.GetObject(); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.EnableSelPrevious(true); go.EnablePreSelect(true, false); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.SetCommandPrompt("Select panels to create dimensions"); while (true) { go.ClearCommandOptions(); // perform the get operation. This will prompt the user to select the list of curves, but also // allow for command line options defined above GetResult result = go.GetMultiple(1, 0); if (result == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (result == GetResult.Number) { continue; } else if (result != GetResult.Object) { } if (go.ObjectsWerePreselected) { go.EnablePreSelect(true, true); break; } break; } int objecTCount = go.ObjectCount; foreach (ObjRef objRef in go.Objects()) //Go through each curve in the objects list { Curve curve = objRef.Curve(); // If curve is null, means objRef is not a curve if (curve == null) { dimensionsCreated = false; continue; } // If curve is not Closed Curve if (curve.IsClosed == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is open"); dimensionsCreated = false; continue; } if (curve.IsPlanar() == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is not planar"); dimensionsCreated = false; continue; } MetrixUtilities.createMetrixRealDimension(); BoundingBox boundingBox = curve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; //Add Horizontal dimension origin = new Point3d(min.X, max.Y, 0); offset = new Point3d(max.X, max.Y, 0); pt = new Point3d((offset.X - origin.X) / 2, max.Y + 180, 0); plane = Plane.WorldXY; plane.Origin = origin; guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension //Add vertical Dimensions origin = new Point3d(min.X, min.Y, 0); offset = new Point3d(min.X, max.Y, 0); //left pt = new Point3d(min.X - 180, (offset.Y - origin.Y) / 2, 0); plane = Plane.WorldXY; plane.XAxis = new Vector3d(0, -1, 0); //-1 to rotate the dimension vertically plane.YAxis = new Vector3d(-1, 0, 0); plane.ZAxis = new Vector3d(0, 0, -1); plane.Origin = origin; guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension dimensionsCreated = true; } doc.Views.Redraw(); //finally redraw to refresh the screen and display dimensions to user return(dimensionsCreated); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { string selectedLayer; Color selectedColour; // For this example we will use a GetPoint class, but all of the custom // "Get" classes support command line options. Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select panels to create borders"); double border = Properties.Settings.Default.PanelBorderDefault; // Default borderSize is 50 // set up the options Rhino.Input.Custom.OptionDouble borderSizeOption = new Rhino.Input.Custom.OptionDouble(border); go.AddOptionDouble("Borders", ref borderSizeOption); go.AcceptNumber(true, true); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.EnableSelPrevious(true); go.EnablePreSelect(true, false); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; RequiredLayer getRequiredLayer = new RequiredLayer(); getRequiredLayer.ShowDialog(); selectedLayer = getRequiredLayer.getLayerName(); selectedColour = getRequiredLayer.getSelectedColor(); while (true) { go.ClearCommandOptions(); borderSizeOption = new Rhino.Input.Custom.OptionDouble(border); go.AddOptionDouble("Borders", ref borderSizeOption); // perform the get operation. This will prompt the user to select the list of curves, but also // allow for command line options defined above GetResult result = go.GetMultiple(1, 0); if (result == GetResult.Option) { border = borderSizeOption.CurrentValue; go.EnablePreSelect(false, true); continue; } else if (result == GetResult.Number) { border = go.Number(); continue; } else if (result != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); continue; } break; } int objecTCount = go.ObjectCount; border = borderSizeOption.CurrentValue; foreach (ObjRef objRef in go.Objects()) { Curve curve = objRef.Curve(); // If curve is null, means objRef is not a curve if (curve == null) { continue; } // If curve is not Closed Curve if (curve.IsClosed == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is open"); continue; } if (curve.IsPlanar() == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is not planar"); continue; } // Process the curve Plane plane = Rhino.Geometry.Plane.WorldXY; Curve[] offsetCurves; int layerIndex = doc.Layers.CurrentLayerIndex; RhinoUtilities.SetActiveLayer(selectedLayer, selectedColour); //if (curve.TryGetPlane(out plane)) //{ if (border < 0) //If the border is negative, it means the border should be drawn outside the perimeter { plane.XAxis = -plane.XAxis; plane.YAxis = -plane.YAxis; plane.ZAxis = -plane.ZAxis; offsetCurves = curve.Offset(plane, border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); } else { offsetCurves = curve.Offset(plane, -border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); } //Check if the curve is outside border and border is a positive if (curve.Contains(offsetCurves[0].PointAtStart, Plane.WorldXY, 0) == PointContainment.Outside && border > 0) { offsetCurves = curve.Offset(plane, border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); //if true, then try to set the curve to be within the border } //Check if the curve is within the border and border is a negative if (curve.Contains(offsetCurves[0].PointAtStart, Plane.WorldXY, 0) == PointContainment.Inside && border < 0) { offsetCurves = curve.Offset(plane, -border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); //if true, then try to set the curve to be outside the border } foreach (Curve c in offsetCurves) { doc.Objects.AddCurve(c); } doc.Layers.SetCurrentLayerIndex(layerIndex, true); } doc.Views.Redraw(); Properties.Settings.Default.PanelBorderDefault = border; Properties.Settings.Default.Save(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // For this example we will use a GetPoint class, but all of the custom // "Get" classes support command line options. Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select panels to create fixing holes"); //get the default values for the properties double holeSize = Properties.Settings.Default.FixingHoleSize; double offsetX = Properties.Settings.Default.FixingHoleOffsetX; double offsetY = Properties.Settings.Default.FixingHoleOffsetY; double spacing = Properties.Settings.Default.FixingHoleSpacing; double minSpacing = Properties.Settings.Default.FixingHoleMinimum; // set up the options Rhino.Input.Custom.OptionDouble holeSizeOption = new Rhino.Input.Custom.OptionDouble(holeSize); Rhino.Input.Custom.OptionDouble offsetXOption = new Rhino.Input.Custom.OptionDouble(offsetX); Rhino.Input.Custom.OptionDouble offsetYOption = new Rhino.Input.Custom.OptionDouble(offsetY); Rhino.Input.Custom.OptionDouble spacingOption = new Rhino.Input.Custom.OptionDouble(spacing); Rhino.Input.Custom.OptionDouble minSpacingOption = new Rhino.Input.Custom.OptionDouble(minSpacing); //using option to get values and save automatically(only if user enters) go.AddOptionDouble("HoleSize", ref holeSizeOption); go.AddOptionDouble("OffsetX", ref offsetXOption); go.AddOptionDouble("OffsetY", ref offsetYOption); go.AddOptionDouble("Spacing", ref spacingOption); go.AddOptionDouble("MinSpacing", ref minSpacingOption); go.AcceptNumber(true, true); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.EnableSelPrevious(true); go.EnablePreSelect(true, false); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; while (true) { go.ClearCommandOptions(); holeSizeOption = new Rhino.Input.Custom.OptionDouble(holeSize); offsetXOption = new Rhino.Input.Custom.OptionDouble(offsetX); offsetYOption = new Rhino.Input.Custom.OptionDouble(offsetY); spacingOption = new Rhino.Input.Custom.OptionDouble(spacing); minSpacingOption = new Rhino.Input.Custom.OptionDouble(minSpacing); go.AddOptionDouble("HoleSize", ref holeSizeOption); go.AddOptionDouble("OffsetX", ref offsetXOption); go.AddOptionDouble("OffsetY", ref offsetYOption); go.AddOptionDouble("Spacing", ref spacingOption); go.AddOptionDouble("MinSpacing", ref minSpacingOption); // perform the get operation. This will prompt the user to select the list of curves, but also // allow for command line options defined above GetResult result = go.GetMultiple(1, 0); if (result == GetResult.Option) { holeSize = holeSizeOption.CurrentValue; offsetX = offsetXOption.CurrentValue; offsetY = offsetYOption.CurrentValue; spacing = spacingOption.CurrentValue; minSpacing = minSpacingOption.CurrentValue; go.EnablePreSelect(false, true); continue; } //else if (result == GetResult.Number) //{ // border = go.Number(); // continue; //} else if (result != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { go.EnablePreSelect(false, true); continue; } break; } int objecTCount = go.ObjectCount; foreach (ObjRef objRef in go.Objects()) { Curve curve = objRef.Curve(); // If curve is null, means objRef is not a curve if (curve == null) { continue; } // If curve is not Closed Curve if (curve.IsClosed == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is open"); continue; } if (curve.IsPlanar() == false) { RhinoApp.WriteLine(objRef.ToString() + " curve is not planar"); continue; } // Find the boundary BoundingBox boundingBox = curve.GetBoundingBox(Plane.WorldXY); Point3d min = boundingBox.Min; Point3d max = boundingBox.Max; List <Point3d> pointsList = new List <Point3d> (); // Calculate top and bottom fixing holes double runningX = min.X + offsetX; //25 double runningY = max.Y - offsetY; //-626.5 Point3d point; while (runningX < (max.X - offsetX) - minSpacing) { point = new Point3d(runningX, runningY, 0); pointsList.Add(point); point = new Point3d(runningX, min.Y + offsetY, 0); pointsList.Add(point); runningX = runningX + spacing; } point = new Point3d(max.X - offsetX, runningY, 0); //adds the top right fixing hole pointsList.Add(point); point = new Point3d(max.X - offsetX, min.Y + offsetY, 0); //adds the bottom right fixing hole pointsList.Add(point); runningY = runningY - spacing; // Calculate the sides while (runningY > (min.Y - offsetY) + minSpacing) { point = new Point3d(min.X + offsetX, runningY, 0); //adds the left fixing holes pointsList.Add(point); point = new Point3d(max.X - offsetX, runningY, 0); //adds the right fixing hole pointsList.Add(point); runningY = runningY - spacing; } // Process the curve Plane plane = Rhino.Geometry.Plane.WorldXY; int layerIndex = doc.Layers.CurrentLayerIndex; RhinoUtilities.SetActiveLayer("Fixing Holes", System.Drawing.Color.Black); // Draw all the holes Round round = new Round(); round.X = holeSize; foreach (Point3d p in pointsList) { round.drawTool(p); } //Round round = new Round(); //round.X = holeSize; //round.drawTool(point); //offsetCurves = curve.Offset(plane, -border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); //if (curve.Contains(offsetCurves[0].PointAtStart, Plane.WorldXY, 0) == PointContainment.Outside) //{ // offsetCurves = curve.Offset(plane, border, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.Sharp); //} //foreach (Curve c in offsetCurves) //{ // doc.Objects.AddCurve(c); //} //// } doc.Layers.SetCurrentLayerIndex(layerIndex, true); } doc.Views.Redraw(); Properties.Settings.Default.FixingHoleSize = holeSize; Properties.Settings.Default.FixingHoleOffsetX = offsetX; Properties.Settings.Default.FixingHoleOffsetY = offsetY; Properties.Settings.Default.FixingHoleSpacing = spacing; Properties.Settings.Default.FixingHoleMinimum = minSpacing; Properties.Settings.Default.Save(); return(Result.Success); }
public static Rhino.Commands.Result GetMultipleWithOptions(Rhino.RhinoDoc doc) { const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; int integer1 = 300; int integer2 = 300; Rhino.Input.Custom.OptionInteger optionInteger1 = new Rhino.Input.Custom.OptionInteger(integer1, 200, 900); Rhino.Input.Custom.OptionInteger optionInteger2 = new Rhino.Input.Custom.OptionInteger(integer2, 200, 900); Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GeometryFilter = geometryFilter; go.AddOptionInteger("Option1", ref optionInteger1); go.AddOptionInteger("Option2", ref optionInteger2); 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) return Rhino.Commands.Result.Cancel; if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } 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; integer1 = optionInteger1.CurrentValue; integer2 = optionInteger2.CurrentValue; Rhino.RhinoApp.WriteLine("Select object count = {0}", objectCount); Rhino.RhinoApp.WriteLine("Value of integer1 = {0}", integer1); Rhino.RhinoApp.WriteLine("Value of integer2 = {0}", integer2); return Rhino.Commands.Result.Success; }
private Tuple <Brep[], Dictionary <int, List <Guid> > > GetObjectsToNest() { //Select Objects To Nest const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Annotation | Rhino.DocObjects.ObjectType.TextDot | Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("OpenNest: Select objects for nesting"); go.GeometryFilter = geometryFilter; go.GroupSelect = false; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(true); go.EnableUnselectObjectsOnExit(true); 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) { return(null);//Rhino.Commands.Result.Cancel; } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } 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(); } List <Guid> guids = new List <Guid>(); for (int i = 0; i < go.ObjectCount; i++) { guids.Add(go.Object(i).ObjectId); } Tuple <Brep[], Dictionary <int, List <Guid> > > data = OpenNestLib.OpenNestUtil.SortGuidsByPlanarCurves(guids, this.cp); Rhino.RhinoApp.WriteLine("OpenNest: Select object count = {0}", go.ObjectCount); this.n = data.Item1.Length; Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); return(data); }