/// <summary> /// Calculates the area of an object /// </summary> public static double GetArea(IRhinoObject obj, double tol) { if (null != obj) { IOnCurve crv = OnCurve.ConstCast(obj.Geometry()); if (null != crv) { return(GetCurveArea(crv, tol)); } IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) { return(GetSurfaceArea(srf)); } IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) { return(GetBrepArea(brep)); } IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) { return(GetMeshArea(mesh)); } } return(0.0); }
/// <summary> /// Calculates the length of an object /// </summary> public static double GetLength(IRhinoObject obj) { double length = 0.0; if (null != obj) { IOnCurve crv = OnCurve.ConstCast(obj.Geometry()); if (null != crv) { crv.GetLength(ref length); } } return(length); }
/// <summary> /// Calculates the volume of an object /// </summary> public static double GetVolume(IRhinoObject obj) { if (null != obj && obj.IsSolid()) { IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) { return(GetSurfaceVolume(srf)); } IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) { return(GetBrepVolume(brep)); } IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) { return(GetMeshVolume(mesh)); } } return(0.0); }
/// <summary> /// Calculates the volume of an object /// </summary> public static double GetVolume(IRhinoObject obj) { if (null != obj && obj.IsSolid()) { IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) return GetSurfaceVolume(srf); IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) return GetBrepVolume(brep); IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) return GetMeshVolume(mesh); } return 0.0; }
/// <summary> /// Calculates the length of an object /// </summary> public static double GetLength(IRhinoObject obj) { double length = 0.0; if (null != obj) { IOnCurve crv = OnCurve.ConstCast(obj.Geometry()); if (null != crv) crv.GetLength(ref length); } return length; }
/// <summary> /// Calculates the area of an object /// </summary> public static double GetArea(IRhinoObject obj, double tol) { if (null != obj) { IOnCurve crv = OnCurve.ConstCast(obj.Geometry()); if (null != crv) return GetCurveArea(crv, tol); IOnSurface srf = OnSurface.ConstCast(obj.Geometry()); if (null != srf) return GetSurfaceArea(srf); IOnBrep brep = OnBrep.ConstCast(obj.Geometry()); if (null != brep) return GetBrepArea(brep); IOnMesh mesh = OnMesh.ConstCast(obj.Geometry()); if (null != mesh) return GetMeshArea(mesh); } return 0.0; }
///<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 tagged object to report"); go.EnableSubObjectSelect(false); go.GetObjects(1, 1); if (go.CommandResult() != IRhinoCommand.result.success) { return(go.CommandResult()); } IRhinoObject obj = go.Object(0).Object(); if (null == obj) { return(IRhinoCommand.result.failure); } IOnGeometry geo = obj.Geometry(); if (null == geo) { return(IRhinoCommand.result.failure); } string[] string_array = null; if (0 == EstimatorHelpers.GetData(obj, ref string_array)) { RhUtil.RhinoApp().Print("No Estimator tag data found.\n"); return(IRhinoCommand.result.nothing); } string filename = null; SaveFileDialog sd = new SaveFileDialog(); sd.DefaultExt = "xml"; sd.Filter = "XML file (*.xml)|*.xml|All files (*.*)|*.*"; 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); } 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 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 i = 0; i < string_array.Length; i++) { writer.WriteElementString("Tag", string_array[i]); } writer.WriteEndElement(); // Tags writer.WriteEndElement(); // Object writer.WriteEndElement(); // Estimator writer.WriteEndDocument(); writer.Flush(); writer.Close(); return(IRhinoCommand.result.success); }