Ejemplo n.º 1
0
        ///<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);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Low level function to get formattted string data from an
 /// object's attribute user string data.
 /// </summary>
 public static int GetData(IRhinoObject obj, ref string string_data)
 {
     if (obj != null)
     {
         if (obj.Attributes().GetUserString(GetKey(), ref string_data))
         {
             return(string_data.Length);
         }
     }
     return(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 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);
        }
Ejemplo n.º 4
0
 /// <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> 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 edge curve");
      go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
      go.GetObjects(1, 1);
      if (go.CommandResult() != IRhinoCommand.result.success)
        return go.CommandResult();

      IRhinoObject obj = go.Object(0).Object();
      IOnBrep brep = go.Object(0).Brep();
      IOnBrepEdge edge = go.Object(0).Edge();
      if (null == obj || null == brep || null == edge)
        return IRhinoCommand.result.failure;

      MRhinoObjectAttributes attribs = new MRhinoObjectAttributes(obj.Attributes());
      if (attribs.GroupCount() > 0)
        attribs.RemoveFromAllGroups();

      for (int i = 0; i < edge.TrimCount(); i++)
      {
        IOnBrepTrim trim = edge.Trim(i);
        if (null != trim)
        {
          IOnBrepFace face = trim.Face();
          if (null != face)
          {
            OnBrep face_brep = brep.DuplicateFace(face.m_face_index, true);
            if (null != face_brep)
            {
              MRhinoBrepObject face_brep_obj = context.m_doc.AddBrepObject(face_brep, attribs);
              if (null != face_brep_obj)
                face_brep_obj.Select();
            }
          }
        }
      }

      context.m_doc.Redraw();

      return IRhinoCommand.result.success;
    }
        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 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>
 /// 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>
 /// Low level function to get formattted string data from an
 /// object's attribute user string data.
 /// </summary>
 public static int GetData(IRhinoObject obj, ref string string_data)
 {
     if (obj != null)
       {
     if (obj.Attributes().GetUserString(GetKey(), ref string_data))
       return string_data.Length;
       }
       return 0;
 }
Ejemplo n.º 10
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);
        }
        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;
        }