/// <summary> /// Add an array of 3-D points to the document /// </summary> public object AddPoints(object pointsObj) { On3dPointArray points = new On3dPointArray(); if (SampleCsRhinoScriptUtils.ConvertToOn3dPointArray(pointsObj, ref points)) { MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); if (null != doc) { ArrayList objectIds = new ArrayList(); for (int i = 0; i < points.Count(); i++) { MRhinoObject rhinoObj = doc.AddPointObject(points[i]); if (null != rhinoObj) { objectIds.Add(rhinoObj.ModelObjectId().ToString()); } } if (objectIds.Count > 0) { doc.Redraw(); return(objectIds.ToArray()); } } } return(null); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoView rhino_view = RhUtil.RhinoApp().ActiveView(); if (null == rhino_view) { return(IRhinoCommand.result.failure); } On3dmView view = new On3dmView(rhino_view.ActiveViewport().View()); view.m_wallpaper_image.Default(); _saved_views.Push(view); int count = _saved_views.Count; if (1 == count) { RhUtil.RhinoApp().Print("The saved view stack has 1 entry.\n"); } else { RhUtil.RhinoApp().Print(string.Format("The saved view stack has {0} entries.\n", count)); } return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { SampleCsDragDropForm form = new SampleCsDragDropForm(); form.Show(RhUtil.RhinoApp().MainWnd()); return(IRhinoCommand.result.success); }
public override bool ExecConduit(ref MRhinoDisplayPipeline dp, uint nChannel, ref bool bTerminate) { if (nChannel == MSupportChannels.SC_DRAWOVERLAY) { if (null != m_brep) { MRhinoViewport vp = dp.GetRhinoVP(); OnColor saved_color = vp.SetDrawColor(RhUtil.RhinoApp().AppSettings().TrackingColor()); for (int i = 0; i < m_points.Count(); i++) { if (i % 100 == 0 && vp.InterruptDrawing()) { break; } On3dPoint pt = m_points[i]; On3dVector dir = new On3dVector(m_normals[i]); if (m_bFlip) { dir.Reverse(); } vp.DrawDirectionArrow(pt, dir); } vp.SetDrawColor(saved_color); } } return(true); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { Rhino3dPointList points = new Rhino3dPointList(); points.Add(new On3dPoint(0, 0, 0)); points.Add(new On3dPoint(0, 0, 1)); points.Add(new On3dPoint(0, 1, 0)); points.Add(new On3dPoint(0, 1, 1)); points.Add(new On3dPoint(1, 0, 0)); points.Add(new On3dPoint(1, 0, 1)); points.Add(new On3dPoint(1, 1, 0)); points.Add(new On3dPoint(1, 1, 1)); RhUtil.RhinoApp().Print("Before sort...\n"); points.Print(); points.Sort(Rhino3dPointList.sort_method.sort_xyz, true); RhUtil.RhinoApp().Print("Sort ascending...\n"); points.Print(); points.Sort(Rhino3dPointList.sort_method.sort_xyz, false); RhUtil.RhinoApp().Print("Sort descending...\n"); points.Print(); context.m_doc.AddPointCloudObject(points.ToPointArray()); context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select solid meshes for volume calculation"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object); go.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.closed_mesh); go.EnableSubObjectSelect(false); go.EnableGroupSelect(); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } List <IOnMesh> meshes = new List <IOnMesh>(); for (int i = 0; i < go.ObjectCount(); i++) { IOnMesh mesh = go.Object(i).Mesh(); if (mesh != null) { meshes.Add(mesh); } } if (meshes.Count == 0) { return(IRhinoCommand.result.nothing); } OnBoundingBox bbox = new OnBoundingBox(); for (int i = 0; i < meshes.Count; i++) { meshes[i].GetBoundingBox(ref bbox, 1); } On3dPoint base_point = bbox.Center(); double total_volume = 0.0; double total_error_estimate = 0.0; string msg; for (int i = 0; i < meshes.Count; i++) { double error_estimate = 0.0; double volume = meshes[i].Volume(base_point, ref error_estimate); msg = string.Format("Mesh {0} = {1:f} (+/- {2:f}\n", i, volume, error_estimate); RhUtil.RhinoApp().Print(msg); total_volume += volume; total_error_estimate += error_estimate; } msg = string.Format("Total volume = {0:f} (+/- {1:f})\n", total_volume, total_error_estimate); RhUtil.RhinoApp().Print(msg); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select two surfaces or polysurfacs to intersect"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object); go.EnableSubObjectSelect(false); go.GetObjects(2, 2); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IOnBrep B0 = go.Object(0).Brep(); IOnBrep B1 = go.Object(1).Brep(); if (null == B0 || null == B1) { return(IRhinoCommand.result.failure); } OnCurve[] curves = null; On3dPointArray points = null; bool rc = RhUtil.RhinoIntersectBreps(B0, B1, context.m_doc.AbsoluteTolerance(), out curves, out points); if ( false == rc || null == curves || 0 == curves.Length || null == points || 0 == curves.Length ) { RhUtil.RhinoApp().Print("No intersections found.\n"); return(IRhinoCommand.result.nothing); } if (null != curves) { for (int i = 0; i < curves.Length; i++) { context.m_doc.AddCurveObject(curves[i]); } } if (null != points) { for (int i = 0; i < points.Count(); i++) { context.m_doc.AddPointObject(points[i]); } } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetString gs = new MRhinoGetString(); gs.SetCommandPrompt("Object name to select"); gs.GetString(); if (gs.CommandResult() != IRhinoCommand.result.success) { return(gs.CommandResult()); } string name = gs.String().Trim(); if (string.IsNullOrEmpty(name)) { return(IRhinoCommand.result.nothing); } MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.normal_objects, IRhinoObjectIterator.object_category.active_and_reference_objects ); int num_selected = 0; IRhinoObject obj = null; for (obj = it.First(); null != obj; obj = it.Next()) { if (name.Equals(obj.Attributes().m_name, StringComparison.OrdinalIgnoreCase)) { obj.Select(true, true, true); num_selected++; } } if (0 == num_selected) { RhUtil.RhinoApp().Print("0 objects selected\n"); } else if (1 == num_selected) { RhUtil.RhinoApp().Print("1 object selected\n"); } else { RhUtil.RhinoApp().Print(string.Format("{0} objects selected\n", num_selected)); } if (0 < num_selected) { context.m_doc.Redraw(); } return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoView view = RhUtil.RhinoApp().ActiveView(); if (null == view) { return(IRhinoCommand.result.failure); } MRhinoViewport vp = view.ActiveViewport(); MRhinoDisplayPipeline dp = view.DisplayPipeline(); MDisplayPipelineAttributes da = view.DisplayAttributes(); // Prevent capturing of the frame buffer on every update MRhinoDisplayPipeline.EnableFrameBufferCapture(false); // Prevent the draw list from updating on every frame dp.FreezeDrawing(true); int dir = 0; // 0 = Right, 1 = Left, 2 = Down, and 3 = Up int frame_count = 100; double delta_angle = 5.0 * (Math.PI / 180.0); for (int i = 0; i < frame_count; i++) { switch (dir) { case 0: vp.LeftRightRotate(delta_angle); break; case 1: vp.LeftRightRotate(-delta_angle); break; case 2: vp.DownUpRotate(delta_angle); break; case 3: vp.DownUpRotate(-delta_angle); break; } //dp.DrawFrameBuffer(da); view.Redraw(); RhUtil.RhinoApp().Wait(0); } dp.FreezeDrawing(false); MRhinoDisplayPipeline.EnableFrameBufferCapture(true); view.Redraw(); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select object"); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } MRhinoObjRef obj_ref = go.Object(0); IRhinoObject obj = obj_ref.Object(); if (null == obj) { return(IRhinoCommand.result.failure); } // 1.) Try the object test RhUtil.RhinoApp().Print("Object Test: "); if (IsLeader(obj)) { RhUtil.RhinoApp().Print("object is a leader.\n"); } else { RhUtil.RhinoApp().Print("object is not a leader.\n"); } // 2.) Try the GUID test RhUtil.RhinoApp().Print("GUID Test: "); if (IsLeader(obj.Attributes().m_uuid)) { RhUtil.RhinoApp().Print("object is a leader.\n"); } else { RhUtil.RhinoApp().Print("object is not a leader.\n"); } // 3.) Try the geometry test RhUtil.RhinoApp().Print("Geometry Test: "); if (IsLeader(obj_ref.Geometry())) { RhUtil.RhinoApp().Print("object is a leader.\n"); } else { RhUtil.RhinoApp().Print("object is not a leader.\n"); } return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn; Dictionary <string, int> map = new Dictionary <string, int>(); MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.undeleted_objects, IRhinoObjectIterator.object_category.active_and_reference_objects); foreach (MRhinoObject obj in it) { string[] string_array = null; if (0 == EstimatorHelpers.GetData(obj, ref string_array)) { continue; } for (int i = 0; i < string_array.Length; i++) { string tag = string_array[i]; int index = plugin.m_tag_table.FindTag(tag); if (index >= 0) { if (plugin.m_tag_table.Tag(index).Type() == EstimatorTag.tag_type.item_tag) { if (!map.ContainsKey(tag)) { map.Add(tag, 1); } else { map[tag]++; } } } } } if (map.Count > 0) { foreach (KeyValuePair <string, int> kvp in map) { RhUtil.RhinoApp().Print(String.Format("Item = {0}, Count = {1}\n", kvp.Key, kvp.Value)); } } else { RhUtil.RhinoApp().Print("No Estimator item tag data found.\n"); } return(IRhinoCommand.result.success); }
public VoxelGrid(RhCommon_Scene ModelSurfaces, List <IOn3dPoint> Pts, int VG_Domain) { VoxelCT = VG_Domain; VoxelInventory = new List <int> [VoxelCT, VoxelCT, VoxelCT]; Voxel = new List <On3dPoint> [VoxelCT, VoxelCT, VoxelCT]; IRhinoObject[] Surfaces = new IRhinoObject[ModelSurfaces.Count()]; OnBoundingBox TightOBox = new OnBoundingBox(); On3dPoint BoxMin = new On3dPoint(); On3dPoint BoxMax = new On3dPoint(); ArrayOn3dPoint Points = new ArrayOn3dPoint(); for (int i = 0; i < Pts.Count; i++) { Points.Append(Pts[i]); } RhUtil.RhinoGetTightBoundingBox(Surfaces, ref TightOBox, false, null); TightOBox.Set(Points, true); OverallBBox = new OnBoundingBox(new On3dPoint(TightOBox.Min().x - 1, TightOBox.Min().y - 1, TightOBox.Min().z - 1), new On3dPoint(TightOBox.Max().x + 1, TightOBox.Max().y + 1, TightOBox.Max().z + 1)); this.X_Incr = (OverallBBox.Max().x - OverallBBox.Min().x) / VoxelCT; this.Y_Incr = (OverallBBox.Max().y - OverallBBox.Min().y) / VoxelCT; this.Z_Incr = (OverallBBox.Max().z - OverallBBox.Min().z) / VoxelCT; //For((int XBox = 0; XBox < VoxelCT; XBox++) Parallel.For(0, VoxelCT, XBox => { RhUtil.RhinoApp().SetStatusBarMessagePane(string.Format("Voxelizing: {0}%", Math.Round((double)XBox / VoxelCT - 1, 2) * 100)); for (int YBox = 0; YBox < VoxelCT; YBox++) { for (int ZBox = 0; ZBox < VoxelCT; ZBox++) { BoxMin = new On3dPoint((OverallBBox.Min().x + this.X_Incr * XBox) - X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * YBox) - Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * ZBox) - Z_Incr / 10); BoxMax = new On3dPoint((OverallBBox.Min().x + this.X_Incr * (XBox + 1)) + X_Incr / 10, (OverallBBox.Min().y + this.Y_Incr * (YBox + 1)) + Y_Incr / 10, (OverallBBox.Min().z + this.Z_Incr * (ZBox + 1)) + X_Incr / 10); this.Voxel[XBox, YBox, ZBox] = new List <On3dPoint>(); this.Voxel[XBox, YBox, ZBox].Add(BoxMin); this.Voxel[XBox, YBox, ZBox].Add(BoxMax); this.VoxelInventory[XBox, YBox, ZBox] = new List <int>(); for (int Index = 0; Index < ModelSurfaces.Count(); Index++) { OnBoundingBox TestBox = new OnBoundingBox(); TestBox = new OnBoundingBox(this.Voxel[XBox, YBox, ZBox][0], this.Voxel[XBox, YBox, ZBox][1]); if (BoxIntersection(ModelSurfaces, TestBox, Index)) { this.VoxelInventory[XBox, YBox, ZBox].Add(Index); } } } } }); }
/// <summary> /// This gets called when when the user runs this command. /// </summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { if (null != _form) { return(IRhinoCommand.result.nothing); } _form = new SampleCsForm(); _form.FormClosed += new FormClosedEventHandler(SampleCsForm_FormClosed); _form.Show(RhUtil.RhinoApp().MainWnd()); return(IRhinoCommand.result.success); }
private void m_listbox_SelectedIndexChanged(object sender, EventArgs e) { if (m_bInEvent) { return; } m_bInSelect = true; MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); // Select what got selected ListBox.SelectedIndexCollection selected = m_listbox.SelectedIndices; // Select what got selected int i = 0; for (i = 0; i < selected.Count; i++) { int index = selected[i]; if (!m_selected.Contains(index)) { Guid guid = new Guid(m_listbox.Items[index].ToString()); MRhinoObject obj = doc.LookupObject(guid); if (obj != null && obj.IsSelectable()) { obj.Select(true); } } } // Unselect what got unselected for (i = 0; i < m_selected.Count; i++) { int index = m_selected[i]; if (!selected.Contains(index)) { Guid guid = new Guid(m_listbox.Items[index].ToString()); MRhinoObject obj = doc.LookupObject(guid); if (obj != null) { obj.Select(false); } } } SaveSelectedIndices(); doc.Redraw(); m_bInSelect = false; }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { for (int i = 0; ; i++) { IOn3dmConstructionPlane cplane = context.m_doc.Properties().NamedConstructionPlane(i); if (null == cplane) { break; } else { RhUtil.RhinoApp().Print(string.Format("Named CPlane {0} = {1}\n", i, cplane.m_name)); } } return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select surface"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object); go.EnableSubObjectSelect(false); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IOnSurface srf = go.Object(0).Surface(); if (null == srf) { return(IRhinoCommand.result.failure); } IOnNurbsSurface ns = srf.NurbsSurface(); if (null == ns) { RhUtil.RhinoApp().Print("Not a NURBS surface.\n"); return(IRhinoCommand.result.nothing); } On3dPoint cv = new On3dPoint(); string str = string.Empty; for (int u = 0; u < ns.CVCount(0); u++) { for (int v = 0; v < ns.CVCount(1); v++) { if (ns.GetCV(u, v, ref cv)) { str = string.Empty; RhUtil.RhinoFormatPoint(cv, ref str); RhUtil.RhinoApp().Print(string.Format("CV({0},{1}) = {2}\n", u, v, str)); } } } return(IRhinoCommand.result.success); }
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.undeleted_objects, IRhinoObjectIterator.object_category.active_and_reference_objects ); for (MRhinoObject obj = it.First(); null != obj; obj = it.Next()) { obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, false); } context.m_doc.Redraw(); RhUtil.RhinoApp().Print("Z-Analysis is off.\n"); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoView view = RhUtil.RhinoApp().ActiveView(); if (null != view) { int left = 0, right = 0, bottom = 0, top = 0; view.ActiveViewport().VP().GetScreenPort(ref left, ref right, ref bottom, ref top); string name = view.ActiveViewport().Name(); int width = right - left; int height = bottom - top; RhUtil.RhinoApp().Print(string.Format("Name = {0}: Width = {1}, Height = {2}\n", name, width, height)); } return(IRhinoCommand.result.cancel); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoView view = RhUtil.RhinoApp().ActiveView(); if (null != view) { // 1/2 of smallest subtended view angle double half_smallest_angle = 0.0; if (view.ActiveViewport().VP().GetCameraAngle(ref half_smallest_angle)) { string fov = string.Empty; RhUtil.RhinoFormatNumber(half_smallest_angle * (180.0 / OnUtil.On_PI), ref fov); RhUtil.RhinoApp().Print(string.Format("Field of view = {0} degrees.\n", fov)); } } return(IRhinoCommand.result.success); }
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select objects for Z analysis"); go.SetGeometryFilter( IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object ); go.GetObjects(1, 0); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } int count = 0; for (int i = 0; i < go.ObjectCount(); i++) { IRhinoObject obj = go.Object(i).Object(); if (null == obj) { continue; } if (obj.InAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID)) { // This object is already in Z analysis mode continue; } if (obj.EnableAnalysisMode(ZAnalysisVAM.ZANALYSIS_VAM_ID, true)) { // A new object is in Z analysis mode count++; } } context.m_doc.Redraw(); RhUtil.RhinoApp().Print(string.Format("{0} objects were put into Z-Analysis mode.\n", count)); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select rectangular light"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IOnLight light = go.Object(0).Light(); if (null == light) { return(IRhinoCommand.result.failure); } if (!light.IsRectangularLight()) { RhUtil.RhinoApp().Print("Not a rectangular light.\n"); return(IRhinoCommand.result.nothing); } On3dPoint origin = light.Location(); On3dVector xaxis = light.Length(); On3dVector yaxis = light.Width(); OnPlane plane = new OnPlane(origin, xaxis, yaxis); OnInterval x_interval = new OnInterval(0.0, xaxis.Length()); OnInterval y_interval = new OnInterval(0.0, yaxis.Length()); OnMesh mesh = RhUtil.RhinoMeshPlane(plane, x_interval, y_interval, 2, 2); if (null != mesh) { mesh.ConvertQuadsToTriangles(); context.m_doc.AddMeshObject(mesh); context.m_doc.Redraw(); } return(IRhinoCommand.result.cancel); }
/// <summary> /// Add a 3-D point to the document /// </summary> public object AddPoint(object pointObj) { On3dPoint point = new On3dPoint(); if (SampleCsRhinoScriptUtils.ConvertToOn3dPoint(pointObj, ref point)) { MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); if (null != doc) { MRhinoObject rhinoObj = doc.AddPointObject(point); if (null != rhinoObj) { doc.Redraw(); return(rhinoObj.ModelObjectId().ToString()); } } } return(null); }
/// <summary> /// This method is called when the drag and drop operation is completed and /// the item being dragged was dropped on a valid, top level Rhino object. /// </summary> public override bool OnDropOnObject(IRhinoObjRef objRef, MRhinoView rhinoView, DataObject data, DragDropEffects dropEffect, Point point) { SampleCsDragData dragData = GetSampleCsDragData(data); if (null == dragData) { return(false); } MessageBox.Show( RhUtil.RhinoApp().MainWnd(), "String \"" + dragData.DragString + "\" Dropped on object", "SampleCsDragDrop", MessageBoxButtons.OK, MessageBoxIcon.Information ); return(true); }
private void button1_Click(object sender, EventArgs e) { // Since our form is modeless, the user can run commands // while our form is visible, including the Open command, // which closes the current document and opens a new one. // Thus, it's best to always ask for the active document // instead of maintaining a reference to the document passed // to the command that created this form. MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); if (null != doc) { On3dPoint a = new On3dPoint(0.0, 0.0, 0.0); On3dPoint b = new On3dPoint(5.0, 5.0, 5.0); OnLine line = new OnLine(a, b); doc.AddCurveObject(line); doc.Redraw(); } }
///<summary> /// This gets called when when the user runs this command. ///</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetFileDialog dlg = new MRhinoGetFileDialog(); if (dlg.DisplayFileDialog(IRhinoGetFileDialog.file_dialog_type.open_text_file_dialog)) { string filename = dlg.FileName(); string line = ""; RhUtil.RhinoApp().Print(string.Format("Opening file {0}.\n", filename)); char[] delim = new char[2]; delim[0] = ','; delim[1] = '\0'; On3dPointArray points = new On3dPointArray(8); StreamReader reader = new StreamReader(filename); line = reader.ReadLine(); while (line != null && line.Length > 0) { string[] substrs = line.Split(delim); if (substrs.Length == 3) { On3dPoint p = new On3dPoint(); p.x = double.Parse(substrs[0]); p.y = double.Parse(substrs[1]); p.z = double.Parse(substrs[2]); points.Append(p); } line = reader.ReadLine(); } OnNurbsCurve curve = RhUtil.RhinoInterpCurve(3, points, null, null, 1); context.m_doc.AddCurveObject(curve); reader.Close(); } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select curve"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object); go.EnableSubObjectSelect(false); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IOnCurve curve = go.Object(0).Curve(); if (null == curve) { return(IRhinoCommand.result.failure); } // Several types of OnCurve objects can have the form of a polyline, // including OnLineCurve, a degree 1 OnNurbsCurve, ON_PolylineCurve, // and ON_PolyCurve (whose segments form a polyline). OnCurve.IsPolyline // tests a curve to see if it can be represented as a polyline. ArrayOn3dPoint points = new ArrayOn3dPoint(64); int point_count = curve.IsPolyline(points); if (point_count > 0) { string point_str = string.Empty; for (int i = 0; i < point_count; i++) { point_str = string.Empty; RhUtil.RhinoFormatPoint(points[i], ref point_str); RhUtil.RhinoApp().Print(string.Format("Point {0} = {1}\n", i, point_str)); } } return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); int count = 0; context.m_doc.UnselectAll(); MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.normal_objects, IRhinoObjectIterator.object_category.active_objects ); IRhinoObject obj = null; for (obj = it.First(); null != obj; obj = it.Next()) { if (obj.IsSolid()) { IOn.object_type type = obj.ObjectType(); if (type == IOn.object_type.surface_object || type == IOn.object_type.brep_object) { obj.Select(true); string fname = string.Format("{0}\\rhino_sat_export_{1}.sat", path, count++); string script = string.Format("_-Export \"{0}\" Inventor _Enter", fname); RhUtil.RhinoApp().RunScript(script, 1); obj.Select(false); } } } context.m_doc.Redraw(); return(IRhinoCommand.result.success); }
/// <summary> /// This method is called when the drag and drop operation is completed and /// the item being dragged was dropped on the Rhino layer list control. /// </summary> public override bool OnDropOnLayerListCtrl(IWin32Window layerListCtrl, int layerIndex, DataObject data, DragDropEffects dropEffect, Point point) { SampleCsDragData dragData = GetSampleCsDragData(data); if (null == dragData) { return(false); } if (layerIndex < 0) { MessageBox.Show( RhUtil.RhinoApp().MainWnd(), "String \"" + dragData.DragString + "\" Dropped on layer list control, not on a layer", "SampleCsDragDrop", MessageBoxButtons.OK, MessageBoxIcon.Information ); } else { MRhinoDoc doc = RhUtil.RhinoApp().ActiveDoc(); if (null != doc && layerIndex < doc.m_layer_table.LayerCount()) { MessageBox.Show( RhUtil.RhinoApp().MainWnd(), "String \"" + dragData.DragString + "\" Dropped on layer \"" + doc.m_layer_table[layerIndex].m_name + "\"", "SampleCsDragDrop", MessageBoxButtons.OK, MessageBoxIcon.Information ); } } return(true); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { List <MRhinoObject> object_list = new List <MRhinoObject>(); MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.undeleted_objects, IRhinoObjectIterator.object_category.active_and_reference_objects); foreach (MRhinoObject obj in it) { string data = null; if (EstimatorHelpers.GetData(obj, ref data) > 0) { object_list.Add(obj); } } if (0 == object_list.Count) { RhUtil.RhinoApp().Print("No objects with Estimator tag data found.\n"); return(IRhinoCommand.result.nothing); } string filename = null; SaveFileDialog sd = new SaveFileDialog(); sd.DefaultExt = "csv"; sd.Filter = "CSV file (*.csv)|*.csv|XML file (*.xml)|*.xml"; sd.AddExtension = true; sd.RestoreDirectory = true; sd.Title = "Save"; if (sd.ShowDialog() == DialogResult.OK) { filename = sd.FileName; } sd.Dispose(); sd = null; if (null == filename) { return(IRhinoCommand.result.cancel); } bool bXml = false; if (Path.GetExtension(filename) == ".xml") { bXml = true; } if (bXml) { XmlTextWriter writer = new XmlTextWriter(filename, Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteComment("Saved on " + DateTime.Now); // Write root element writer.WriteStartElement("Estimator"); writer.WriteAttributeString("Version", "1.0"); // Write objects element writer.WriteStartElement("Objects"); writer.WriteAttributeString("Count", object_list.Count.ToString()); for (int i = 0; i < object_list.Count; i++) { MRhinoObject obj = object_list[i]; if (null == obj) { continue; } IOnGeometry geo = obj.Geometry(); if (null == geo) { continue; } string[] string_array = null; if (0 == EstimatorHelpers.GetData(obj, ref string_array)) { continue; } // Write object writer.WriteStartElement("Object"); writer.WriteAttributeString("Type", geo.ObjectType().ToString()); writer.WriteElementString("Uuid", obj.Attributes().m_uuid.ToString()); if (obj.Attributes().m_name.Length > 0) { writer.WriteElementString("Name", obj.Attributes().m_name); } else { writer.WriteElementString("Name", "(none)"); } // Write object length double length = EstimatorHelpers.GetLength(obj); if (length > 0.0) { writer.WriteElementString("Length", length.ToString()); } else { writer.WriteElementString("Length", "n/a"); } double tol = context.m_doc.AbsoluteTolerance(); // Write object area double area = EstimatorHelpers.GetArea(obj, tol); if (area > 0.0) { writer.WriteElementString("Area", area.ToString()); } else { writer.WriteElementString("Area", "n/a"); } // Write object volume double volume = EstimatorHelpers.GetVolume(obj); if (volume > 0.0) { writer.WriteElementString("Volume", volume.ToString()); } else { writer.WriteElementString("Volume", "n/a"); } // Write object tags writer.WriteStartElement("Tags"); for (int j = 0; j < string_array.Length; j++) { writer.WriteElementString("Tag", string_array[j]); } writer.WriteEndElement(); // Tags writer.WriteEndElement(); // Object } writer.WriteEndElement(); // Objects writer.WriteEndElement(); // Estimator writer.WriteEndDocument(); writer.Flush(); writer.Close(); } else { TextWriter writer = new StreamWriter(filename); for (int i = 0; i < object_list.Count; i++) { MRhinoObject obj = object_list[i]; if (null == obj) { continue; } IOnGeometry geo = obj.Geometry(); if (null == geo) { continue; } string[] string_array = null; if (0 == EstimatorHelpers.GetData(obj, ref string_array)) { continue; } StringBuilder sb = new StringBuilder(); sb.Append(geo.ObjectType().ToString()); sb.Append(","); sb.Append(obj.Attributes().m_uuid.ToString()); sb.Append(","); double length = EstimatorHelpers.GetLength(obj); if (length > 0.0) { sb.Append(length.ToString()); } else { sb.Append("n/a"); } sb.Append(","); double tol = context.m_doc.AbsoluteTolerance(); double area = EstimatorHelpers.GetArea(obj, tol); if (area > 0.0) { sb.Append(area.ToString()); } else { sb.Append("n/a"); } sb.Append(","); double volume = EstimatorHelpers.GetVolume(obj); if (volume > 0.0) { sb.Append(volume.ToString()); } else { sb.Append("n/a"); } for (int j = 0; j < string_array.Length; j++) { sb.Append(","); sb.Append(string_array[j]); } writer.WriteLine(sb.ToString()); } // close the stream writer.Close(); } return(IRhinoCommand.result.success); }
///<summary> This gets called when when the user runs this command.</summary> public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Get the name of the instance definition to rename MRhinoGetString gs = new MRhinoGetString(); gs.SetCommandPrompt("Name of block to rename"); gs.GetString(); if (gs.CommandResult() != IRhinoCommand.result.success) { return(gs.CommandResult()); } // Validate string string idef_name = gs.String().Trim(); if (string.IsNullOrEmpty(idef_name)) { return(IRhinoCommand.result.nothing); } // Verify instance definition exists MRhinoInstanceDefinitionTable idef_table = context.m_doc.m_instance_definition_table; int idef_index = idef_table.FindInstanceDefinition(idef_name); if (idef_index < 0) { RhUtil.RhinoApp().Print(string.Format("Block \"{0}\" not found.\n", idef_name)); return(IRhinoCommand.result.nothing); } // Verify instance definition is rename-able IRhinoInstanceDefinition idef = idef_table[idef_index]; if (idef.IsDeleted() || idef.IsReference()) { RhUtil.RhinoApp().Print(string.Format("Unable to rename block \"{0}\".\n", idef_name)); return(IRhinoCommand.result.nothing); } // Get the new instance definition name gs.SetCommandPrompt("New block name"); gs.GetString(); if (gs.CommandResult() != IRhinoCommand.result.success) { return(gs.CommandResult()); } // Validate string string new_idef_name = gs.String().Trim(); if (string.IsNullOrEmpty(new_idef_name)) { return(IRhinoCommand.result.nothing); } // Verify the new instance definition name is not already in use int new_idef_index = idef_table.FindInstanceDefinition(new_idef_name); if (new_idef_index >= 0 && new_idef_index < idef_table.InstanceDefinitionCount()) { if (!idef_table[new_idef_index].IsDeleted()) { RhUtil.RhinoApp().Print(string.Format("Block \"{0}\" already exists.\n", new_idef_name)); return(IRhinoCommand.result.nothing); } } // Make a copy of the instance definition object OnInstanceDefinition new_idef = new OnInstanceDefinition(idef); // Rename the copy new_idef.SetName(new_idef_name); // Modify the existing instance definition with our copy if (idef_table.ModifyInstanceDefinition(new_idef, idef_index, (uint)idef_settings.idef_name_setting, false)) { return(IRhinoCommand.result.success); } return(IRhinoCommand.result.failure); }