///<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; }
private void SampleCsObjectManagerControl_Load(object sender, EventArgs e) { m_events.Register(); m_events.Enable(true); MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.undeleted_objects, IRhinoObjectIterator.object_category.active_and_reference_objects ); it.IncludeLights(true); it.IncludeGrips(false); m_listbox.BeginUpdate(); for (MRhinoObject obj = it.First(); obj != null; obj = it.Next()) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.Items.Add(guid.ToString()); if (obj.IsSelected() > 0) { m_listbox.SetSelected(index, true); } } m_listbox.EndUpdate(); SaveSelectedIndices(); }
///<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) { 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 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; }
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) { 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; }
///<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) { 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 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); }
private void SampleCsObjectManagerControl_Load(object sender, EventArgs e) { m_events.Register(); m_events.Enable(true); MRhinoObjectIterator it = new MRhinoObjectIterator( IRhinoObjectIterator.object_state.undeleted_objects, IRhinoObjectIterator.object_category.active_and_reference_objects ); it.IncludeLights(true); it.IncludeGrips(false); m_listbox.BeginUpdate(); for (MRhinoObject obj = it.First(); obj != null; obj = it.Next()) { Guid guid = obj.Attributes().m_uuid; int index = m_listbox.Items.Add(guid.ToString()); if (obj.IsSelected() > 0) m_listbox.SetSelected(index, true); } m_listbox.EndUpdate(); SaveSelectedIndices(); }
//writing to file //returns true if we have any data to wite /*public override bool CallWriteDocument(IRhinoFileWriteOptions options) { //only return true if you REALLY want to save something to the document //that is about to be written to disk if (options.Mode(IRhinoFileWriteOptions.ModeFlag.SelectedMode) == true) return false; if (options.Mode(IRhinoFileWriteOptions.ModeFlag.AsVersion2) == true) return false; if (options.Mode(IRhinoFileWriteOptions.ModeFlag.AsVersion3) == true) return false; //perform some other type of check to see if you need to save any data... //If( IHaveDataToWrite() = False ) Then Return False return false; } //If any ON_BinaryArchive::Write*() functions return false than you should //immediately return false otherwise return true if all data was written //successfully. Returning false will cause Rhino to stop writing this document. public override bool WriteDocument(MRhinoDoc doc, OnBinaryArchive archive, IRhinoFileWriteOptions options) { //This function is called because CallWriteDocument returned True. //Write your plug-in data to the document string date_string = System.DateTime.Now.ToShortDateString(); string time_string = System.DateTime.Now.ToShortTimeString(); ///It is a good idea to always start with a version number //so you can modify your document read/write code in the future if (archive.Write3dmChunkVersion(1, 0) == false) return false; if (archive.WriteString(date_string) == false) return false; if (archive.WriteString(time_string) == false) return false; return true; }*/ public override IRhinoCommand.result Render(RMA.Rhino.IRhinoCommandContext context, bool render_preview) { /*RenderSettings settings = new RenderSettings(); if (settings.ShowDialog() == DialogResult.OK)*/ { //use . instead of cz , for floats in String.Format System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CreateSpecificCulture("en"); //todo: more elegant MRhinoObjectIterator it = new MRhinoObjectIterator(context.m_doc, IRhinoObjectIterator.object_state.normal_or_locked_objects, IRhinoObjectIterator.object_category.active_and_reference_objects); it.IncludeLights(false); it.IncludePhantoms(false); //fill list with objects from iterator List<IRhinoObject> objs = new List<IRhinoObject>(); foreach (MRhinoObject obj in it) { objs.Add(obj); } //mesh selected objects from list IRhinoAppRenderMeshSettings rms = RhUtil.RhinoApp().AppSettings().RenderMeshSettings(); OnMeshParameters mp = new OnMeshParameters(rms.FastMeshParameters()); int ui_style = 1; // simple ui ArrayMRhinoObjectMesh meshes = new ArrayMRhinoObjectMesh(); IRhinoCommand.result rc = RhUtil.RhinoMeshObjects(objs.ToArray(), ref mp, ref ui_style, ref meshes); //if anything was meshed: if (rc == IRhinoCommand.result.success) { // open file FileStream file = new FileStream("scene.xml", FileMode.Create, FileAccess.Write); TextWriter tw = new StreamWriter(file); tw.WriteLine("<?xml version=\"1.0\"?>"); tw.WriteLine("<scene type=\"triangle\">"); //materials tw.WriteLine(materials.serialize()); /*if (materialDefinition.Trim() != "") { materialName = material.m_material_id.ToString(); tw.WriteLine(string.Format(ci, "<material name=\"{0}\">", materialName)); tw.WriteLine(materialDefinition); tw.WriteLine("</material>"); }*/ /*tw.WriteLine("<material name=\"defaultMat\">"); tw.WriteLine(" <type sval=\"shinydiffusemat\"/>"); tw.WriteLine("</material>");*/ // write meshes geometry // todo: normals for (int i = 0; i < meshes.Count(); i++) { IRhinoMaterial material = meshes[i].m_parent_object.ObjectMaterial(); string materialName = ""; material.GetUserString("yafaray_material", ref materialName); if (materialName == "") materialName = "defaultMat"; string meshObject = writeMeshObject(meshes[i], materialName); tw.WriteLine(meshObject); //TODO: get somewhere smoothing angle, or better rhino should generate normals... tw.WriteLine(string.Format(ci, "<smooth ID=\"{0}\" angle=\"30\"/>", i + 1)); } tw.WriteLine(cameraFromActiveViewport()); //todo: scene setting dialog tw.WriteLine("<background name=\"world_background\">"); tw.WriteLine(" <a_var fval=\"1\"/>"); tw.WriteLine(" <add_sun bval=\"true\"/>"); tw.WriteLine(" <b_var fval=\"1\"/>"); tw.WriteLine(" <background_light bval=\"true\"/>"); tw.WriteLine(" <c_var fval=\"1\"/>"); tw.WriteLine(" <d_var fval=\"1\"/>"); tw.WriteLine(" <e_var fval=\"1\"/>"); tw.WriteLine(" <from x=\"1\" y=\"1\" z=\"1\"/>"); tw.WriteLine(" <light_samples ival=\"8\"/>"); tw.WriteLine(" <power fval=\"1\"/>"); tw.WriteLine(" <sun_power fval=\"1\"/>"); tw.WriteLine(" <turbidity fval=\"3\"/>"); tw.WriteLine(" <type sval=\"sunsky\"/>"); tw.WriteLine("</background>"); tw.WriteLine(""); tw.WriteLine("<integrator name=\"default\">"); tw.WriteLine(" <caustics bval=\"false\"/>"); tw.WriteLine(" <raydepth ival=\"4\"/>"); tw.WriteLine(" <shadowDepth ival=\"4\"/>"); tw.WriteLine(" <transpShad bval=\"false\"/>"); tw.WriteLine(" <type sval=\"directlighting\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine(""); tw.WriteLine("<integrator name=\"default2\">"); tw.WriteLine(" <caustics bval=\"false\"/>"); tw.WriteLine(" <raydepth ival=\"4\"/>"); tw.WriteLine(" <shadowDepth ival=\"4\"/>"); tw.WriteLine(" <transpShad bval=\"false\"/>"); tw.WriteLine(" <type sval=\"directlighting\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"volintegr\">"); tw.WriteLine(" <type sval=\"none\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"default3\">"); tw.WriteLine(" <caustics bval=\"false\"/>"); tw.WriteLine(" <raydepth ival=\"4\"/>"); tw.WriteLine(" <shadowDepth ival=\"4\"/>"); tw.WriteLine(" <transpShad bval=\"false\"/>"); tw.WriteLine(" <type sval=\"directlighting\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"volintegr\">"); tw.WriteLine(" <type sval=\"none\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"default4\">"); tw.WriteLine(" <caustics bval=\"false\"/>"); tw.WriteLine(" <raydepth ival=\"4\"/>"); tw.WriteLine(" <shadowDepth ival=\"4\"/>"); tw.WriteLine(" <transpShad bval=\"false\"/>"); tw.WriteLine(" <type sval=\"directlighting\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"volintegr\">"); tw.WriteLine(" <type sval=\"none\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"default5\">"); tw.WriteLine(" <caustics bval=\"false\"/>"); tw.WriteLine(" <raydepth ival=\"4\"/>"); tw.WriteLine(" <shadowDepth ival=\"4\"/>"); tw.WriteLine(" <transpShad bval=\"false\"/>"); tw.WriteLine(" <type sval=\"directlighting\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"volintegr\">"); tw.WriteLine(" <type sval=\"none\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"default6\">"); tw.WriteLine(" <caustics bval=\"false\"/>"); tw.WriteLine(" <raydepth ival=\"4\"/>"); tw.WriteLine(" <shadowDepth ival=\"4\"/>"); tw.WriteLine(" <transpShad bval=\"false\"/>"); tw.WriteLine(" <type sval=\"directlighting\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"volintegr\">"); tw.WriteLine(" <type sval=\"none\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"default7\">"); tw.WriteLine(" <caustics bval=\"false\"/>"); tw.WriteLine(" <raydepth ival=\"4\"/>"); tw.WriteLine(" <shadowDepth ival=\"4\"/>"); tw.WriteLine(" <transpShad bval=\"false\"/>"); tw.WriteLine(" <type sval=\"directlighting\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine("<integrator name=\"volintegr\">"); tw.WriteLine(" <type sval=\"none\"/>"); tw.WriteLine("</integrator>"); tw.WriteLine(""); tw.WriteLine("<render>"); tw.WriteLine(" <AA_inc_samples ival=\"1\"/>"); tw.WriteLine(" <AA_minsamples ival=\"1\"/>"); tw.WriteLine(" <AA_passes ival=\"1\"/>"); tw.WriteLine(" <AA_pixelwidth fval=\"1.5\"/>"); tw.WriteLine(" <AA_threshold fval=\"0.05\"/>"); tw.WriteLine(" <background_name sval=\"world_background\"/>"); tw.WriteLine(" <camera_name sval=\"cam\"/>"); tw.WriteLine(" <clamp_rgb bval=\"false\"/>"); tw.WriteLine(" <filter_type sval=\"box\"/>"); tw.WriteLine(" <gamma fval=\"1.8\"/>"); tw.WriteLine(" <height ival=\"600\"/>"); tw.WriteLine(" <integrator_name sval=\"default\"/>"); tw.WriteLine(" <threads ival=\"1\"/>"); tw.WriteLine(" <volintegrator_name sval=\"volintegr\"/>"); tw.WriteLine(" <width ival=\"800\"/>"); tw.WriteLine(" <xstart ival=\"0\"/>"); tw.WriteLine(" <ystart ival=\"0\"/>"); tw.WriteLine(" <z_channel bval=\"true\"/>"); tw.WriteLine("</render>"); tw.WriteLine("</scene>"); tw.Close(); file.Close(); //run yafaray //todo: configurable path System.Diagnostics.Process objProcess = new Process(); ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c \"c:\\Program Files\\YafaRay\\yafaray-xml.exe\" scene.xml"); Process.Start(psi); 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) { 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> /// 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); }
/// <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; }