public override void OnReplaceObject(ref MRhinoDoc doc, ref MRhinoObject old, ref MRhinoObject obj) { if (_mainUI != null) { _mainUI.Whatever(); } }
public int ExplodeHatch(MRhinoDoc doc, Guid hatchGuid, ref List<Guid> objectGuids) { int objectGuids_Count = objectGuids.Count; if (null != doc) { IRhinoHatch hatchObject = MRhinoHatch.ConstCast(doc.LookupObject(hatchGuid)); if (null != hatchObject) { MRhinoObject[] subObjects = null; int subObjects_Count = hatchObject.GetSubObjects(out subObjects); if (0 < subObjects_Count || null != subObjects) { for (int i = 0; i < subObjects_Count; i++) { bool rc = doc.AddObject(subObjects[i]); if (rc) objectGuids.Add(subObjects[i].Attributes().m_uuid); } } } } return objectGuids.Count - objectGuids_Count; }
public int ExplodeHatch(MRhinoDoc doc, Guid hatchGuid, ref List <Guid> objectGuids) { int objectGuids_Count = objectGuids.Count; if (null != doc) { IRhinoHatch hatchObject = MRhinoHatch.ConstCast(doc.LookupObject(hatchGuid)); if (null != hatchObject) { MRhinoObject[] subObjects = null; int subObjects_Count = hatchObject.GetSubObjects(out subObjects); if (0 < subObjects_Count || null != subObjects) { for (int i = 0; i < subObjects_Count; i++) { bool rc = doc.AddObject(subObjects[i]); if (rc) { objectGuids.Add(subObjects[i].Attributes().m_uuid); } } } } } return(objectGuids.Count - objectGuids_Count); }
public override void OnCloseDocument(ref MRhinoDoc doc) { if (true == m_control.Visible) { m_control.OnCloseDocument(ref doc); } }
public override void OnDeselectObjects(ref MRhinoDoc doc, IRhinoObject[] objects) { if (true == m_control.Visible) { m_control.OnDeselectObjects(ref doc, objects); } }
/// <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); }
public override void OnDeselectAllObjects(ref MRhinoDoc doc, int count) { if (true == m_control.Visible) { m_control.OnDeselectAllObjects(ref doc, count); } }
public override void OnSelectObject(ref MRhinoDoc doc, IRhinoObject @object) { if (true == m_control.Visible) { m_control.OnSelectObject(ref doc, @object); } }
public override void OnDeleteObject(ref MRhinoDoc doc, ref MRhinoObject @object) { if (true == m_control.Visible) { m_control.OnDeleteObject(ref doc, ref @object); } }
public override void OnReplaceObject(ref MRhinoDoc doc, ref MRhinoObject old, ref MRhinoObject obj, Splash splashScreen) { // to access the instance of the class from here, // pass in the variable that holds a reference to the instance splashScreen.[Whatever];
string GetUnusedInstanceDefinitionName(MRhinoDoc doc) { string idef_name = string.Empty; doc.m_instance_definition_table.GetUnusedInstanceDefinitionName(ref idef_name); return(idef_name); }
public void OnCloseDocument(ref MRhinoDoc doc) { if (m_bInSelect) return; m_bInEvent = true; m_listbox.Items.Clear(); SaveSelectedIndices(); m_bInEvent = false; }
public void OnDeselectAllObjects(ref MRhinoDoc doc, int count) { if (m_bInSelect) { return; } m_bInEvent = true; m_listbox.ClearSelected(); SaveSelectedIndices(); m_bInEvent = false; }
public void OnCloseDocument(ref MRhinoDoc doc) { if (m_bInSelect) { return; } m_bInEvent = true; m_listbox.Items.Clear(); SaveSelectedIndices(); m_bInEvent = false; }
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; }
public void OnDeleteObject(ref MRhinoDoc doc, ref MRhinoObject obj) { if (m_bInSelect) return; m_bInEvent = true; Guid guid = obj.Attributes().m_uuid; string str = guid.ToString(); int index = m_listbox.FindStringExact(str); if (index != ListBox.NoMatches) m_listbox.Items.RemoveAt(index); SaveSelectedIndices(); m_bInEvent = false; }
/// <summary> /// Low level function to set formattted string data to an /// object's attribute user string data. /// </summary> public static bool SetData(IRhinoObject obj, string string_data) { if (obj != null) { MRhinoDoc doc = obj.Document(); if (doc != null) { MRhinoObjectAttributes atts = new MRhinoObjectAttributes(obj.Attributes()); if (atts.SetUserString(GetKey(), string_data)) { return(doc.ModifyObjectAttributes(new MRhinoObjRef(obj), atts)); } } } return(false); }
/// <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); }
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(); } }
public void OnDeleteObject(ref MRhinoDoc doc, ref MRhinoObject obj) { if (m_bInSelect) { return; } m_bInEvent = true; Guid guid = obj.Attributes().m_uuid; string str = guid.ToString(); int index = m_listbox.FindStringExact(str); if (index != ListBox.NoMatches) { m_listbox.Items.RemoveAt(index); } SaveSelectedIndices(); m_bInEvent = false; }
public void OnDeselectObject(ref MRhinoDoc doc, IRhinoObject obj) { if (m_bInSelect) { return; } m_bInEvent = true; if (obj != null) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.FindStringExact(guid.ToString()); if (index != ListBox.NoMatches) { m_listbox.SetSelected(index, false); } } SaveSelectedIndices(); m_bInEvent = false; }
/// <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); }
public void OnSelectObjects(ref MRhinoDoc doc, IRhinoObject[] objects) { if (m_bInSelect) { return; } m_bInEvent = true; for (int i = 0; i < objects.Length; i++) { IRhinoObject obj = objects[i]; if (obj != null) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.FindStringExact(guid.ToString()); if (index != ListBox.NoMatches) { m_listbox.SetSelected(index, true); } } } SaveSelectedIndices(); m_bInEvent = false; }
/// <summary> /// Rhino calls WriteFile() to write document geometry to an external file. /// </summary> public override int WriteFile(string filename, int index, ref MRhinoDoc doc, ref IRhinoFileWriteOptions options) { int rc = 0; // false // Are we saving or exporting? bool bExport = options.Mode(IRhinoFileWriteOptions.ModeFlag.SelectedMode); // Are we in interactive or scripted mode? bool bScript = options.Mode(IRhinoFileWriteOptions.ModeFlag.BatchMode); List<IRhinoObject> objects = new List<IRhinoObject>(); // Get objects to save/export MRhinoObjectIterator it = new MRhinoObjectIterator(doc, IRhinoObjectIterator.object_state.undeleted_objects); if (bExport) { it.EnableSelectedFilter(); it.EnableVisibleFilter(); } // Do the iteration... MRhinoObject obj = null; for (obj = it.First(); null != obj; obj = it.Next()) objects.Add(obj); ArrayMRhinoObjectMesh meshes = new ArrayMRhinoObjectMesh(objects.Count); OnMeshParameters mesh_parameters = _mesh_parameters; int mesh_ui_style = (bScript) ? 2 : _mesh_ui_style; // Get the meshes to save/export IRhinoCommand.result res = RhUtil.RhinoMeshObjects(objects.ToArray(), ref mesh_parameters, ref mesh_ui_style, ref meshes); if (res == IRhinoCommand.result.success) { if (mesh_ui_style >= 0 && mesh_ui_style <= 1) _mesh_ui_style = mesh_ui_style; _mesh_parameters = mesh_parameters; } else { if (bExport) RhUtil.RhinoApp().Print("No meshes to export.\n"); else RhUtil.RhinoApp().Print("No meshes to save.\n"); return rc; } try { // Open the file System.IO.StreamWriter file = new System.IO.StreamWriter(filename); // Write mesh count file.WriteLine(string.Format("meshcount={0}\n", meshes.Count())); // Write each mesh for (int i = 0; i < meshes.Count(); i++) { MRhinoObjectMesh obj_mesh = meshes[i]; OnMesh mesh = obj_mesh.GetMesh(); if (null != mesh) { // Write mesh number file.WriteLine(string.Format("mesh={0}\n", i)); // Write mesh vertex count file.WriteLine(string.Format("vertexcount={0}\n", mesh.m_V.Count())); // Write mesh face count file.WriteLine(string.Format("facecount={0}\n", mesh.m_F.Count())); // Write mesh vertices for (int vi = 0; vi < mesh.m_V.Count(); vi++) { On3fPoint p = mesh.m_V[vi]; file.WriteLine(string.Format("vertex=({0},{1},{2})\n", p.x, p.y, p.z)); } // Write mesh faces for (int fi = 0; fi < mesh.m_F.Count(); fi++) { OnMeshFace f = mesh.m_F[fi]; file.WriteLine(string.Format("face=({0},{1},{2},{3})\n", f.get_vi(0), f.get_vi(1), f.get_vi(2), f.get_vi(3))); } } } file.Close(); rc = 1; // true } catch (Exception e) { RhUtil.RhinoApp().Print(string.Format("{0}\n", e.Message)); } return rc; }
int CreateInstanceDefinition(MRhinoDoc doc, IOnInstanceDefinition idef, IOn3dPoint point, List<IRhinoObject> objects, bool bQuietly) { int found_index = doc.m_instance_definition_table.FindInstanceDefinition(idef.Name(), true); List<IRhinoObject> idef_objects = new List<IRhinoObject>(); OnXform xform = new OnXform(); xform.Translation(new On3dPoint(OnUtil.On_origin) - point); for (int i = 0; i < objects.Count; i++) { IRhinoObject obj = objects[i]; if (obj == null) continue; if (obj.ObjectType() == IOn.object_type.light_object || obj.ObjectType() == IOn.object_type.grip_object || obj.ObjectType() == IOn.object_type.phantom_object ) continue; // Transform geometry and attributes, but do not add to the document MRhinoObject dupe = doc.TransformObject(obj, xform, false, false, false); if (dupe != null) { if (doc.AddObject(dupe, false, true)) idef_objects.Add(dupe); } } if (idef_objects.Count < 1) return -1; int idef_index = -1; if (found_index < 0) idef_index = doc.m_instance_definition_table.AddInstanceDefinition(idef, idef_objects.ToArray(), false, bQuietly); else if (doc.m_instance_definition_table.ModifyInstanceDefinitionGeometry(found_index, idef_objects.ToArray(), bQuietly)) { idef_index = found_index; doc.m_instance_definition_table.ModifyInstanceDefinition(idef, idef_index, (uint)IDEF_SETTINGS.all_idef_settings, bQuietly); if (!bQuietly) { IRhinoInstanceObject[] iref_object_list = null; int iref_count = doc.m_instance_definition_table[found_index].GetReferences(out iref_object_list); if (iref_count > 0) RhUtil.RhinoApp().Print(string.Format("{0} Instances of block \"{1}\" have been updated.\n", iref_count, idef.Name())); } } if (idef_index < 0 && !bQuietly) { string message = (found_index < 0) ? "Error creating block.\n" : "Error modifying block.\n"; RhUtil.RhinoApp().Print(message); } return idef_index; }
string GetUnusedInstanceDefinitionName(MRhinoDoc doc) { string idef_name = string.Empty; doc.m_instance_definition_table.GetUnusedInstanceDefinitionName(ref idef_name); return idef_name; }
int CreateInstanceDefinition(MRhinoDoc doc, IOnInstanceDefinition idef, IOn3dPoint point, List <IRhinoObject> objects, bool bQuietly) { int found_index = doc.m_instance_definition_table.FindInstanceDefinition(idef.Name(), true); List <IRhinoObject> idef_objects = new List <IRhinoObject>(); OnXform xform = new OnXform(); xform.Translation(new On3dPoint(OnUtil.On_origin) - point); for (int i = 0; i < objects.Count; i++) { IRhinoObject obj = objects[i]; if (obj == null) { continue; } if (obj.ObjectType() == IOn.object_type.light_object || obj.ObjectType() == IOn.object_type.grip_object || obj.ObjectType() == IOn.object_type.phantom_object ) { continue; } // Transform geometry and attributes, but do not add to the document MRhinoObject dupe = doc.TransformObject(obj, xform, false, false, false); if (dupe != null) { if (doc.AddObject(dupe, false, true)) { idef_objects.Add(dupe); } } } if (idef_objects.Count < 1) { return(-1); } int idef_index = -1; if (found_index < 0) { idef_index = doc.m_instance_definition_table.AddInstanceDefinition(idef, idef_objects.ToArray(), false, bQuietly); } else if (doc.m_instance_definition_table.ModifyInstanceDefinitionGeometry(found_index, idef_objects.ToArray(), bQuietly)) { idef_index = found_index; doc.m_instance_definition_table.ModifyInstanceDefinition(idef, idef_index, (uint)IDEF_SETTINGS.all_idef_settings, bQuietly); if (!bQuietly) { IRhinoInstanceObject[] iref_object_list = null; int iref_count = doc.m_instance_definition_table[found_index].GetReferences(out iref_object_list); if (iref_count > 0) { RhUtil.RhinoApp().Print(string.Format("{0} Instances of block \"{1}\" have been updated.\n", iref_count, idef.Name())); } } } if (idef_index < 0 && !bQuietly) { string message = (found_index < 0) ? "Error creating block.\n" : "Error modifying block.\n"; RhUtil.RhinoApp().Print(message); } return(idef_index); }
public override void OnCloseDocument(ref MRhinoDoc doc) { if (true == m_control.Visible) m_control.OnCloseDocument(ref doc); }
/// <summary> /// Rhino calls WriteFile() to write document geometry to an external file. /// </summary> public override int WriteFile(string filename, int index, ref MRhinoDoc doc, ref IRhinoFileWriteOptions options) { int rc = 0; // false // Are we saving or exporting? bool bExport = options.Mode(IRhinoFileWriteOptions.ModeFlag.SelectedMode); // Are we in interactive or scripted mode? bool bScript = options.Mode(IRhinoFileWriteOptions.ModeFlag.BatchMode); List <IRhinoObject> objects = new List <IRhinoObject>(); // Get objects to save/export MRhinoObjectIterator it = new MRhinoObjectIterator(doc, IRhinoObjectIterator.object_state.undeleted_objects); if (bExport) { it.EnableSelectedFilter(); it.EnableVisibleFilter(); } // Do the iteration... MRhinoObject obj = null; for (obj = it.First(); null != obj; obj = it.Next()) { objects.Add(obj); } ArrayMRhinoObjectMesh meshes = new ArrayMRhinoObjectMesh(objects.Count); OnMeshParameters mesh_parameters = _mesh_parameters; int mesh_ui_style = (bScript) ? 2 : _mesh_ui_style; // Get the meshes to save/export IRhinoCommand.result res = RhUtil.RhinoMeshObjects(objects.ToArray(), ref mesh_parameters, ref mesh_ui_style, ref meshes); if (res == IRhinoCommand.result.success) { if (mesh_ui_style >= 0 && mesh_ui_style <= 1) { _mesh_ui_style = mesh_ui_style; } _mesh_parameters = mesh_parameters; } else { if (bExport) { RhUtil.RhinoApp().Print("No meshes to export.\n"); } else { RhUtil.RhinoApp().Print("No meshes to save.\n"); } return(rc); } try { // Open the file System.IO.StreamWriter file = new System.IO.StreamWriter(filename); // Write mesh count file.WriteLine(string.Format("meshcount={0}\n", meshes.Count())); // Write each mesh for (int i = 0; i < meshes.Count(); i++) { MRhinoObjectMesh obj_mesh = meshes[i]; OnMesh mesh = obj_mesh.GetMesh(); if (null != mesh) { // Write mesh number file.WriteLine(string.Format("mesh={0}\n", i)); // Write mesh vertex count file.WriteLine(string.Format("vertexcount={0}\n", mesh.m_V.Count())); // Write mesh face count file.WriteLine(string.Format("facecount={0}\n", mesh.m_F.Count())); // Write mesh vertices for (int vi = 0; vi < mesh.m_V.Count(); vi++) { On3fPoint p = mesh.m_V[vi]; file.WriteLine(string.Format("vertex=({0},{1},{2})\n", p.x, p.y, p.z)); } // Write mesh faces for (int fi = 0; fi < mesh.m_F.Count(); fi++) { OnMeshFace f = mesh.m_F[fi]; file.WriteLine(string.Format("face=({0},{1},{2},{3})\n", f.get_vi(0), f.get_vi(1), f.get_vi(2), f.get_vi(3))); } } } file.Close(); rc = 1; // true } catch (Exception e) { RhUtil.RhinoApp().Print(string.Format("{0}\n", e.Message)); } return(rc); }
public void OnDeselectObject(ref MRhinoDoc doc, IRhinoObject obj) { if (m_bInSelect) return; m_bInEvent = true; if (obj != null) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.FindStringExact(guid.ToString()); if (index != ListBox.NoMatches) m_listbox.SetSelected(index, false); } SaveSelectedIndices(); m_bInEvent = false; }
public override void OnDeleteObject(ref MRhinoDoc doc, ref MRhinoObject @object) { if (true == m_control.Visible) m_control.OnDeleteObject(ref doc, ref @object); }
public void OnDeselectAllObjects(ref MRhinoDoc doc, int count) { if (m_bInSelect) return; m_bInEvent = true; m_listbox.ClearSelected(); SaveSelectedIndices(); m_bInEvent = false; }
public override void OnDeselectAllObjects(ref MRhinoDoc doc, int count) { if (true == m_control.Visible) m_control.OnDeselectAllObjects(ref doc, count); }
public override void OnSelectObject(ref MRhinoDoc doc, IRhinoObject @object) { if (true == m_control.Visible) m_control.OnSelectObject(ref doc, @object); }
public void OnSelectObjects(ref MRhinoDoc doc, IRhinoObject[] objects) { if (m_bInSelect) return; m_bInEvent = true; for (int i = 0; i < objects.Length; i++) { IRhinoObject obj = objects[i]; if (obj != null) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.FindStringExact(guid.ToString()); if (index != ListBox.NoMatches) m_listbox.SetSelected(index, true); } } SaveSelectedIndices(); m_bInEvent = false; }
public override void OnSelectObjects(ref MRhinoDoc doc, IRhinoObject[] objects) { if (true == m_control.Visible) m_control.OnSelectObjects(ref doc, objects); }