Пример #1
0
        ///<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)
        {
            RhinoGetVolumeObjects go = new RhinoGetVolumeObjects();

            go.SetCommandPrompt("Select objects to apply area tags");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            EstimatorTagForm form = new EstimatorTagForm();

            form.m_str_title  = "Add Volume Tags";
            form.m_str_prompt = "Select one or more volume tags.";
            form.m_type       = EstimatorTag.tag_type.volume_tag;

            DialogResult rc = form.ShowDialog();

            if (rc == DialogResult.Cancel)
            {
                return(IRhinoCommand.result.cancel);
            }

            List <string> tag_strings = new List <string>(form.m_selected_tags.Count);

            EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn;
            int             i      = 0;

            for (i = 0; i < form.m_selected_tags.Count; i++)
            {
                int index = form.m_selected_tags[i];
                tag_strings.Add(plugin.m_tag_table[index].Id());
            }

            for (i = 0; i < go.ObjectCount(); i++)
            {
                EstimatorHelpers.AddData(go.Object(i).Object(), tag_strings.ToArray());
            }

            return(IRhinoCommand.result.success);
        }
Пример #3
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 objects to apply item tag");
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            EstimatorTagForm form = new EstimatorTagForm();

            form.m_str_title  = "Add Item Tag";
            form.m_str_prompt = "Select an item tag.";
            form.m_type       = EstimatorTag.tag_type.item_tag;

            DialogResult rc = form.ShowDialog();

            if (rc == DialogResult.Cancel)
            {
                return(IRhinoCommand.result.cancel);
            }

            List <string> tag_strings = new List <string>(form.m_selected_tags.Count);

            EstimatorPlugIn plugin = RMA.Rhino.RhUtil.GetPlugInInstance() as EstimatorPlugIn;
            int             i      = 0;

            for (i = 0; i < form.m_selected_tags.Count; i++)
            {
                int index = form.m_selected_tags[i];
                tag_strings.Add(plugin.m_tag_table[index].Id());
            }

            for (i = 0; i < go.ObjectCount(); i++)
            {
                EstimatorHelpers.RemoveAllData(go.Object(i).Object());
                EstimatorHelpers.AddData(go.Object(i).Object(), tag_strings.ToArray());
            }

            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);
        }
Пример #5
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);
        }