protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "glTF 1.0/2.0 binary (ShapeDiver) (*.glb)"; dlg.DefaultExt = ".glb"; dlg.Title = "Save glTF file"; dlg.FileName = "Export.glb"; var result = dlg.ShowSaveDialog(); var filename = dlg.FileName; if (result) { string strCommand = @"_-Export " + filename + " Enter"; RhinoApp.RunScript(strCommand, false); } if (serverManager.IsRunning) { serverManager.Broadcast(filename); } return(Result.Success); }
/// <summary> /// Add an array of 3-D points to the document /// </summary> public object AddPoints(object pointsObj) { List <Rhino.Geometry.Point3d> points = new List <Rhino.Geometry.Point3d>(); if (SampleRhinoHelpers.ConvertToPoint3dList(pointsObj, ref points)) { Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc; if (null != doc) { ArrayList objectIds = new ArrayList(); for (int i = 0; i < points.Count(); i++) { System.Guid objectId = doc.Objects.AddPoint(points[i]); if (!objectId.Equals(System.Guid.Empty)) { objectIds.Add(objectId.ToString()); } } if (objectIds.Count > 0) { doc.Views.Redraw(); return(objectIds.ToArray()); } } } return(null); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { GetObject go = Selection.GetValidExportObjects("Select objects to export."); var dialog = GetSaveFileDialog(); var fileSelected = dialog.ShowSaveDialog(); if (!fileSelected) { return(Result.Cancel); } bool binary = GlTFUtils.IsFileGltfBinary(dialog.FileName); if (!GetExportOptions(mode, out glTFExportOptions opts)) { return(Result.Cancel); } Rhino.DocObjects.RhinoObject[] rhinoObjects = go.Objects().Select(o => o.Object()).ToArray(); if (!DoExport(dialog.FileName, opts, binary, doc, rhinoObjects, doc.RenderSettings.LinearWorkflow)) { return(Result.Failure); } return(Result.Success); }
public Rhino.Commands.Result GetPoints(Rhino.RhinoDoc doc) { // Input interval var input = new Rhino.Input.Custom.GetNumber(); // Select surface var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select point"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Point; go.GetMultiple(1, 1); Rhino.Geometry.Point pt = go.Object(0).Point(); Rhino.Geometry.Point3d pointA = pt.Location; go.SetCommandPrompt("Select surface"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface; go.GetMultiple(1, 1); Rhino.Geometry.Surface surfaceB = go.Object(0).Surface(); double u, v; if (surfaceB.ClosestPoint(pointA, out u, out v)) { Rhino.Geometry.Point3d pointC = surfaceB.PointAt(u, v); Rhino.Geometry.Vector3d vector = pointA - pointC; // write list pointD } return(Rhino.Commands.Result.Success); }
// Use this for initialization void Start() { ResolveEventHandler OnRhinoCommonResolve = null; AppDomain.CurrentDomain.AssemblyResolve += OnRhinoCommonResolve = (sender, args) => { const string rhinoCommonAssemblyName = "RhinoCommon"; var assemblyName = new AssemblyName(args.Name).Name; if (assemblyName != rhinoCommonAssemblyName) { return(null); } AppDomain.CurrentDomain.AssemblyResolve -= OnRhinoCommonResolve; string rhinoSystemDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Rhino WIP", "System"); return(Assembly.LoadFrom(Path.Combine(rhinoSystemDir, rhinoCommonAssemblyName + ".dll"))); }; //rhinoCore = new RhinoCore(new string[] { $"/scheme=UNITY", "/nosplash", "/runscript=\"_Grasshopper\"" }, WindowStyle.Normal); rhinoCore = new RhinoCore(new string[] { $"/scheme=UNITY", "/nosplash" }, WindowStyle.Normal); doc = Rhino.RhinoDoc.ActiveDoc; SceneToRhino(); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { const Rhino.DocObjects.ObjectType selFilter = Rhino.DocObjects.ObjectType.Point; Rhino.DocObjects.ObjRef[] pointObjRefs; Result getPointsResults = RhinoGet.GetMultipleObjects("Select circuit component endpoints", false, selFilter, out pointObjRefs); if (getPointsResults == Result.Success) { RhinoList <Point> circuitPoints = new RhinoList <Point>(); foreach (Rhino.DocObjects.ObjRef objRef in pointObjRefs) { circuitPoints.Add(objRef.Point()); } RhinoList <Line> conduitLines = autoroute(circuitPoints); foreach (Line conduitLine in conduitLines) { doc.Objects.AddLine(conduitLine); } doc.Views.Redraw(); return(Result.Success); } return(Result.Failure); }
protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode) { var type = typeof(VR_PANEL); Rhino.UI.Panels.OpenPanel(type.GUID); return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { const ObjectType geometryFilter = ObjectType.Mesh; GetObject go = new GetObject(); go.SetCommandPrompt("Select meshes to compute contacts"); go.GeometryFilter = geometryFilter; go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; GetResult res = go.GetMultiple(1, 0); if (res != GetResult.Object) { return(Result.Cancel); } Rhino.RhinoApp.WriteLine(res.GetType().ToString()) return(Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { Rhino.Input.Custom.GetObject getobjects = new Rhino.Input.Custom.GetObject(); getobjects.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; getobjects.AcceptNothing(false); switch (getobjects.GetMultiple(1, 0)) { case GetResult.ExitRhino: return(Result.ExitRhino); case GetResult.Cancel: return(Result.Cancel); case GetResult.Object: if (getobjects.ObjectCount > 1) { Rhino.DocObjects.ObjRef[] arrCurve = getobjects.Objects(); Array.Sort(arrCurve, (x, y) => x.Curve().GetLength().CompareTo(y.Curve().GetLength())); doc.Objects.Delete(arrCurve[0], true); } return(Result.Success); default: return(Result.Failure); } }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { GetObject go = Selection.GetValidExportObjects("Select objects to export."); var dialog = GetSaveFileDialog(); var fileSelected = dialog.ShowSaveDialog(); if (!fileSelected) { return(Result.Cancel); } bool binary = GlTFUtils.IsFileGltfBinary(dialog.FileName); var opts = new glTFExportOptions() { UseDracoCompression = false, DracoCompressionLevel = 10, DracoQuantizationBitsPosition = 11, DracoQuantizationBitsNormal = 8, DracoQuantizationBitsTexture = 10, UseBinary = binary }; if (mode == RunMode.Scripted) { Rhino.Input.RhinoGet.GetBool("Compression", true, "None", "Draco", ref opts.UseDracoCompression); if (opts.UseDracoCompression) { Rhino.Input.RhinoGet.GetInteger("Draco Compression Level (max=10)", true, ref opts.DracoCompressionLevel, 1, 10); Rhino.Input.RhinoGet.GetInteger("Quantization Position", true, ref opts.DracoQuantizationBitsPosition, 8, 32); Rhino.Input.RhinoGet.GetInteger("Quantization Normal", true, ref opts.DracoQuantizationBitsNormal, 8, 32); Rhino.Input.RhinoGet.GetInteger("Quantization Texture", true, ref opts.DracoQuantizationBitsTexture, 8, 32); } Rhino.Input.RhinoGet.GetBool("Map Rhino Z to glTF Y", true, "No", "Yes", ref opts.MapRhinoZToGltfY); } else { ExportOptionsDialog optionsDlg = new ExportOptionsDialog(opts); if (optionsDlg.ShowModal() == null) { return(Result.Cancel); } } var rhinoObjects = go .Objects() .Select(o => o.Object()) .ToArray(); if (!DoExport(dialog.FileName, opts, rhinoObjects, doc.RenderSettings.LinearWorkflow)) { return(Result.Failure); } return(Result.Success); }
static public bool CreateSections(Rhino.RhinoDoc doc, Rhino.Geometry.GeometryBase geo, Rhino.Geometry.Surface surfaceB, Rhino.Geometry.Curve curve, double interval, ref List <PlanePoint> points) { Rhino.Geometry.Interval domain = curve.Domain; // fixed issue for (double t = domain.T0; t < domain.T1; t += interval) { Rhino.Geometry.Point3d pt = curve.PointAt(t); Rhino.Geometry.Vector3d tangent = curve.TangentAt(t); Rhino.Geometry.Vector3d curvature = curve.CurvatureAt(t); Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(); curve.FrameAt(t, out plane); doc.Objects.AddPoint(pt); curvature = curvature * 10.0; Rhino.Geometry.Line line = new Rhino.Geometry.Line(pt, curvature); doc.Objects.AddLine(line); RhinoApp.WriteLine("Curve at {0}", t); Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(); bool ret = false; if (geo is Rhino.Geometry.Brep) { Rhino.Geometry.Brep brepA = (Rhino.Geometry.Brep)geo; ret = GetNormalVector(brepA, pt, ref normal); RhinoApp.WriteLine(" Added Brep point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z); } else if (geo is Rhino.Geometry.Surface) { Rhino.Geometry.Surface surfaceA = (Rhino.Geometry.Surface)geo; ret = GetNormalVector(surfaceA, pt, ref normal); RhinoApp.WriteLine(" Added surface point at ({0}, {0}, {0})", pt.X, pt.Y, pt.Z); } if (ret) { Rhino.Geometry.Vector3d ucoord = CrossProduct(tangent, normal); Rhino.Geometry.Plane plane2 = new Rhino.Geometry.Plane(pt, ucoord, tangent); // normal); double[] parameters = plane2.GetPlaneEquation(); PlanePoint PlanePoint = new PlanePoint(); PlanePoint.pt = pt; PlanePoint.A = parameters[0]; PlanePoint.B = parameters[1]; PlanePoint.C = parameters[2]; PlanePoint.D = parameters[3]; PlanePoint.curvature = curvature; points.Add(PlanePoint); Rhino.Geometry.Interval Interval1 = new Rhino.Geometry.Interval(-0.1, -0.1); Rhino.Geometry.Interval Interval2 = new Rhino.Geometry.Interval(0.1, 0.1); Rhino.Geometry.PlaneSurface PlaneSurface = new Rhino.Geometry.PlaneSurface(plane2, Interval1, Interval2); doc.Objects.AddSurface(PlaneSurface); } } return(true); }
public static Rhino.Commands.Result ObjectDisplayMode(Rhino.RhinoDoc doc) { const ObjectType filter = ObjectType.Mesh | ObjectType.Brep; ObjRef objref; Result rc = Rhino.Input.RhinoGet.GetOneObject("Select mesh or surface", true, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Guid viewportId = doc.Views.ActiveView.ActiveViewportID; ObjectAttributes attr = objref.Object().Attributes; if (attr.HasDisplayModeOverride(viewportId)) { RhinoApp.WriteLine("Removing display mode override from object"); attr.RemoveDisplayModeOverride(viewportId); } else { Rhino.Display.DisplayModeDescription[] modes = Rhino.Display.DisplayModeDescription.GetDisplayModes(); Rhino.Display.DisplayModeDescription mode = null; if (modes.Length == 1) { mode = modes[0]; } else { Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Select display mode"); string[] str_modes = new string[modes.Length]; for (int i = 0; i < modes.Length; i++) { str_modes[i] = modes[i].EnglishName.Replace(" ", "").Replace("-", ""); } go.AddOptionList("DisplayMode", str_modes, 0); if (go.Get() == Rhino.Input.GetResult.Option) { mode = modes[go.Option().CurrentListOptionIndex]; } } if (mode == null) { return(Rhino.Commands.Result.Cancel); } attr.SetDisplayModeOverride(mode, viewportId); } doc.Objects.ModifyAttributes(objref, attr, false); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
//RhinoDoc doc; public static Rhino.Commands.Result AddCircle(Rhino.RhinoDoc doc) { Rhino.Geometry.Point3d center = new Rhino.Geometry.Point3d(0, 0, 0); const double radius = 10.0; Rhino.Geometry.Circle c = new Rhino.Geometry.Circle(center, radius); if (doc.Objects.AddCircle(c) != Guid.Empty) { doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
/// <summary> /// Registers all the input parameters for this component. /// </summary> protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { Rhino.RhinoDoc Doc = Rhino.RhinoDoc.ActiveDoc; pManager.AddCurveParameter("Curve", "C", "需要标注的曲线", GH_ParamAccess.item); pManager.AddPlaneParameter("Plane", "P", "标注所在工作平面", GH_ParamAccess.item, Plane.WorldXY); pManager.AddNumberParameter("Offset", "O", "标注偏移距离", GH_ParamAccess.item, 10); pManager.AddTextParameter("DimStyle", "D", "标注样式", GH_ParamAccess.item); pManager.AddTextParameter("Text", "T", "文字", GH_ParamAccess.item, Id); pManager[1].Optional = true; pManager[2].Optional = true; pManager[4].Optional = true; }
/// <summary> /// Called by Rhino to "run" your command. /// </summary> protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { var rc = Result.Success; var first = First; rc = Rhino.Input.RhinoGet.GetInteger("First number to add", false, ref first); if (rc != Result.Success) { return(rc); } var second = Second; rc = Rhino.Input.RhinoGet.GetNumber("Second number to add", false, ref second); if (rc != Result.Success) { return(rc); } var result = RhinoMath.UnsetValue; try { result = UnsafeNativeMethods.Add(first, second); } catch (Exception ex) { RhinoApp.WriteLine(ex.Message); return(Result.Failure); } var str = string.Format("{0} + {1} = {2}", first, second, result); if (mode == RunMode.Interactive) { Rhino.UI.Dialogs.ShowMessage(str, EnglishName); } else { RhinoApp.WriteLine(str); } First = first; Second = second; return(Result.Success); }
public void BakeGeometry(Rhino.RhinoDoc doc, Rhino.DocObjects.ObjectAttributes att, List <Guid> obj_ids) { if (att == null) { att = doc.CreateDefaultAttributes(); } foreach (IGH_BakeAwareObject item in m_data) { if (item != null) { List <Guid> idsOut = new List <Guid>(); item.BakeGeometry(doc, att, idsOut); obj_ids.AddRange(idsOut); } } }
public Rhino.Commands.Result delete(Rhino.RhinoDoc doc) { // Input incomplate double _incomplate = 0.1; var input = new Rhino.Input.Custom.GetNumber(); input.SetCommandPrompt("Input incomplate(0.0 ~ 1.0)<0.1>"); Rhino.Input.GetResult res = input.Get(); if (res == Rhino.Input.GetResult.Number) { _incomplate = input.Number(); } if (_incomplate == 0.0) { _incomplate = 0.1; } // Select surface var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select elements"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Point; res = go.GetMultiple(1, 1024 * 10); if (res == Rhino.Input.GetResult.Nothing) { return(Rhino.Commands.Result.Failure); } System.Collections.Generic.List <Guid> list = new System.Collections.Generic.List <Guid>(); for (int i = 0; i < go.ObjectCount; i++) { Guid guid = go.Object(i).ObjectId; list.Add(guid); } int deleteCount = (int)((double)(list.Count) * _incomplate); Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects; for (int i = 0; i < deleteCount; i++) { Guid guid = list[i]; ot.Delete(guid, true); } return(Rhino.Commands.Result.Success); }
private List <Mesh> FindAnalysisGrid() { List <Mesh> anlysisGrid = new List <Mesh>(); try { string layerName = "Analysis Grid"; Rhino.RhinoDoc activeDoc = Rhino.RhinoDoc.ActiveDoc; activeDoc.Objects.UnselectAll(); List <Guid> objIds = new List <Guid>(); if (null != activeDoc) { int layerIndex = activeDoc.Layers.Find(layerName, true); if (layerIndex < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, layerName + " cannot be found."); return(null); } Rhino.DocObjects.Layer layer = activeDoc.Layers[layerIndex]; Rhino.DocObjects.RhinoObject[] objs = activeDoc.Objects.FindByLayer(layer); if (objs != null) { foreach (Rhino.DocObjects.RhinoObject obj in objs) { if (obj.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Mesh) { Mesh mesh = obj.Geometry as Mesh; if (null != mesh) { anlysisGrid.Add(mesh); Guid guid = obj.Id; objIds.Add(guid); } } } activeDoc.Objects.Select(objIds); } } } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Analysis Grid cannot be exported.\n" + ex.Message); } return(anlysisGrid); }
/// <summary> /// Rhino calls this function to run the command. /// </summary> protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode) { const Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Curve; Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select curve to divide", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Curve curve = objref.Curve(); if (null == curve || curve.IsShort(Rhino.RhinoMath.ZeroTolerance)) { return(Rhino.Commands.Result.Failure); } int segmentCount = 2; rc = Rhino.Input.RhinoGet.GetInteger("Number of segments", false, ref segmentCount, 2, 100); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Geometry.Point3d[] points; curve.DivideByCount(segmentCount, true, out points); if (null == points) { return(Rhino.Commands.Result.Failure); } // Create a history record Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, _historyVersion); WriteHistory(history, objref, segmentCount, points.Length); for (int i = 0; i < points.Length; i++) { doc.Objects.AddPoint(points[i], null, history, false); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { #if IncludeSample // TODO: start here modifying the behaviour of your command. // --- RhinoApp.WriteLine("The {0} command will add a line right now.", EnglishName); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the start point"); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No start point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the end point"); getPointAction.SetBasePoint(pt0, true); getPointAction.DrawLineFromPoint(pt0, true); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No end point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); } doc.Objects.AddLine(pt0, pt1); doc.Views.Redraw(); RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName); return(Result.Success); #else // TODO: start here modifying the behaviour of your command. return(Result.Success); #endif }
/// <summary> /// bake an object in the given rhino document /// </summary> /// <param name="doc">document to bake into</param> /// <param name="att">attributes to bake with (should not be null)</param> /// <param name="obj_guid">the id of the baked object</param> /// <returns>true on success. ifalse, obj_guid and obj_inst are not guaranteed to be valid pointers</returns> public bool BakeGeometry(Rhino.RhinoDoc doc, Rhino.DocObjects.ObjectAttributes att, out Guid obj_guid) { obj_guid = Guid.Empty; if (Value == null) { return(false); } if (!Value.IsValid) { return(false); } doc.Objects.AddMesh(Value.Display); return(true); }
/// <summary> /// Add a 3-D point to the document /// </summary> public object AddPoint(object pointObj) { Rhino.Geometry.Point3d point = new Rhino.Geometry.Point3d(); if (SampleRhinoHelpers.ConvertToPoint3d(pointObj, ref point)) { Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc; if (null != doc) { System.Guid objectId = doc.Objects.AddPoint(point); if (!objectId.Equals(System.Guid.Empty)) { doc.Views.Redraw(); return(objectId.ToString()); } } } return(null); }
public static Rhino.Commands.Result IntersectCurves(Rhino.RhinoDoc doc) { // Select two curves to intersect var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select two curves"); go.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; go.GetMultiple(2, 2); if (go.CommandResult() != Rhino.Commands.Result.Success) { return(go.CommandResult()); } // Validate input var curveA = go.Object(0).Curve(); var curveB = go.Object(1).Curve(); if (curveA == null || curveB == null) { return(Rhino.Commands.Result.Failure); } // Calculate the intersection const double intersection_tolerance = 0.001; const double overlap_tolerance = 0.0; var events = Rhino.Geometry.Intersect.Intersection.CurveCurve(curveA, curveB, intersection_tolerance, overlap_tolerance); // Process the results if (events != null) { for (int i = 0; i < events.Count; i++) { var ccx_event = events[i]; doc.Objects.AddPoint(ccx_event.PointA); if (ccx_event.PointA.DistanceTo(ccx_event.PointB) > double.Epsilon) { doc.Objects.AddPoint(ccx_event.PointB); doc.Objects.AddLine(ccx_event.PointA, ccx_event.PointB); } } doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
private int getLayerOrCreate(Rhino.RhinoDoc doc, string name) { int layer_index = 0; Rhino.DocObjects.Layer layer = doc.Layers.FindName(name); Guid current_layer_guid = doc.Layers.CurrentLayer.Id; if (layer == null) { Rhino.DocObjects.Layer newlayer = new Rhino.DocObjects.Layer(); newlayer.ParentLayerId = current_layer_guid; newlayer.Name = name; layer_index = doc.Layers.Add(newlayer); } else { layer_index = layer.Index; } return(layer_index); }
public SchemaObjectFilter(List <RhinoObject> docObjects, Rhino.RhinoDoc doc, string inputSchema = null) { Doc = doc; // add all supported enums to schema dict foreach (SupportedSchema schema in Enum.GetValues(typeof(SupportedSchema))) { SchemaDictionary.Add(schema.ToString(), new List <RhinoObject>()); } if (inputSchema == null) // no schema means automagic processing { ApplyNamingFilter(docObjects, out List <RhinoObject> unfilteredObjs); ApplyGeomFilter(unfilteredObjs); } else { ApplyGeomFilter(docObjects, inputSchema); } }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { if (!serverManager.IsRunning) { RhinoApp.WriteLine("Server is not running"); return(Result.Cancel); } GetString getString = new GetString(); getString.SetCommandPrompt("Send the message"); GetResult result = getString.Get(); if (getString.CommandResult() != Result.Success) { return(getString.CommandResult()); } serverManager.Broadcast(getString.StringResult()); return(Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { // TODO: start here modifying the behaviour of your command. // --- RhinoApp.WriteLine("The {0} command will select the curve with same length", EnglishName); double tolerance = 0.001; Rhino.Commands.Result rc = Rhino.Commands.Result.Failure; using (GetObject getObjectAction = new GetObject()) { getObjectAction.GeometryFilter = ObjectType.Curve; getObjectAction.SetCommandPrompt("Please select curves"); var dblOption = new OptionDouble(tolerance, true, 0); getObjectAction.AddOptionDouble("SelectionTolerance", ref dblOption); getObjectAction.EnablePreSelect(true, true); var result = getObjectAction.Get(); double refLength = 0.0; if (result == GetResult.Object) { var value = getObjectAction.Object(0); var crv = value.Curve(); if (crv != null) { refLength = crv.GetLength(); var objects = doc.Objects.FindByObjectType(ObjectType.Curve); foreach (var obj in objects) { var _curve = (new ObjRef(obj)).Curve(); if (Rhino.RhinoMath.EpsilonEquals(_curve.GetLength(), refLength, dblOption.CurrentValue)) { obj.Select(true); } } rc = Rhino.Commands.Result.Success; } } } doc.Views.Redraw(); return(rc); }
protected override Result RunCommand(Rhino.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); Point3d pt0; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the start point"); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No start point was selected."); return(getPointAction.CommandResult()); } pt0 = getPointAction.Point(); } Point3d pt1; using (GetPoint getPointAction = new GetPoint()) { getPointAction.SetCommandPrompt("Please select the end point"); getPointAction.SetBasePoint(pt0, true); getPointAction.DrawLineFromPoint(pt0, true); if (getPointAction.Get() != GetResult.Point) { RhinoApp.WriteLine("No end point was selected."); return(getPointAction.CommandResult()); } pt1 = getPointAction.Point(); } Rhino.Geometry.Line line1 = new Line(pt0, pt1); doc.Objects.AddLine(line1); doc.Views.Redraw(); RhinoApp.WriteLine("The {0} command added one line to the document.", EnglishName); RhinoApp.WriteLine("The distance between the two points is {0} {1}.", line1.Length, doc.ModelUnitSystem.ToString().ToLower()); return(Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { var apartmentHousesPercetage = new double(); var population = new double(); ObjRef[] srcCurves; RhinoGet.GetMultipleObjects("ClosedPolygones", false, ObjectType.Curve, out srcCurves); RhinoGet.GetNumber("Insert population", false, ref population, 0, 1000000); RhinoGet.GetNumber("Percent of population living in apartment houses", false, ref apartmentHousesPercetage, 0, 100000); var dicts = new Dictionary <Guid, DataDto>(); for (var i = 0; i < srcCurves.Count(); i++) { var o = GetDto(srcCurves[i]); dicts.Add(srcCurves[i].ObjectId, o); } var optimalLivingArea = GetOptimalLivingArea((int)Math.Round(population), (int)Math.Round(apartmentHousesPercetage)); var excistingLivingArea = GetExcistingLivingArea(dicts); if (optimalLivingArea > 0 && excistingLivingArea > 0) { var overStockPercent = (excistingLivingArea - optimalLivingArea) * 100 / excistingLivingArea; RhinoApp.WriteLine($"Overstock {overStockPercent} percent"); } else { RhinoApp.WriteLine($"No info to calculate overstock percent"); } return(Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { var dirname = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string[] pathComponent = new string[] { dirname.ToString(), @"common_paper_sizes.json" }; var jsonPath = Path.Combine(pathComponent); GetPoint gp = new GetPoint(); string text = System.IO.File.ReadAllText(jsonPath); gp.SetCommandPrompt("Set Origin of Paper Rectangle"); OptionToggle boolOption = new OptionToggle(false, "Off", "On"); gp.AddOptionToggle("Portrait", ref boolOption); var listNames = new List <string>(); var listValues = new List <Point2d>(); List <Paper> papers = JsonConvert.DeserializeObject <List <Paper> >(text); //foreach(var paper in papers) //{ var count = 0; foreach (var format in papers[0].formats) { var num = int.Parse(Regex.Match(format.name, @"\d+").Value); if (num < 6 && !format.name.Contains("C")) { listNames.Add(format.name); listValues.Add(new Point2d(format.size.mm[0], format.size.mm[1])); count++; } } //} var listNamesArr = listNames.ToArray(); int listIndex = 0; int opList = gp.AddOptionList("PaperType", listNamesArr, listIndex); while (true) { // perform the get operation. This will prompt the user to input a point, but also // allow for command line options defined above Rhino.Input.GetResult get_rc = gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } if (get_rc == Rhino.Input.GetResult.Point) { var plane = doc.Views.ActiveView.ActiveViewport.GetConstructionPlane().Plane; plane.Origin = gp.Point(); var item = listValues[listIndex]; var isPortrait = boolOption.CurrentValue; var rect = new Rectangle3d(plane, isPortrait ? item.X : item.Y, isPortrait ? item.Y : item.X); var attr = new Rhino.DocObjects.ObjectAttributes(); attr.Name = listNames[listIndex]; attr.LayerIndex = doc.Layers.CurrentLayerIndex; doc.Objects.AddRectangle(rect, attr); doc.Views.Redraw(); } else if (get_rc == Rhino.Input.GetResult.Option) { if (gp.OptionIndex() == opList) { listIndex = gp.Option().CurrentListOptionIndex; } continue; } break; } return(Rhino.Commands.Result.Success); }