///<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 surface edge");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.edge_object);
            go.EnableSubObjectSelect();
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref   = go.Object(0);
            IOnBrepEdge  brep_edge = obj_ref.Edge();

            if (null == brep_edge)
            {
                return(IRhinoCommand.result.failure);
            }

            IOnBrep brep = brep_edge.Brep();

            if (null == brep)
            {
                return(IRhinoCommand.result.failure);
            }

            // TODO: add functionality here...

            return(IRhinoCommand.result.success);
        }
 bool IsLeader(Guid guid)
 {
     bool rc = false;
       MRhinoObjRef obj_ref = new MRhinoObjRef(guid);
       IRhinoObject obj = obj_ref.Object();
       if (null != obj)
     rc = IsLeader(obj);
       return rc;
 }
        ///<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);
        }
        bool IsLeader(Guid guid)
        {
            bool         rc      = false;
            MRhinoObjRef obj_ref = new MRhinoObjRef(guid);
            IRhinoObject obj     = obj_ref.Object();

            if (null != obj)
            {
                rc = IsLeader(obj);
            }
            return(rc);
        }
Пример #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 object to move");
            go.EnableSubObjectSelect(false);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Point to move from");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint pointFrom = gp.Point();

            gp.SetCommandPrompt("Point to move to");
            gp.SetBasePoint(pointFrom);
            gp.DrawLineFromPoint(pointFrom, true);
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint pointTo = gp.Point();

            On3dVector dir = new On3dVector(pointTo - pointFrom);

            if (dir.IsTiny())
            {
                return(IRhinoCommand.result.nothing);
            }

            OnXform xform = new OnXform();

            xform.Translation(dir);

            MRhinoObjRef objectRef = go.Object(0);

            context.m_doc.TransformObject(ref objectRef, xform);
            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
Пример #6
0
        /// <summary>
        /// This gets called when when the user runs this command.
        /// </summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select objects to animate
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to animate");
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Select path curve
            MRhinoGetObject gc = new MRhinoGetObject();

            gc.SetCommandPrompt("Select path curve");
            gc.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            gc.SetGeometryAttributeFilter(IRhinoGetObject.GEOMETRY_ATTRIBUTE_FILTER.open_curve);
            gc.EnableDeselectAllBeforePostSelect(false);
            gc.GetObjects(1, 1);
            if (gc.CommandResult() != IRhinoCommand.result.success)
            {
                return(gc.CommandResult());
            }

            // Get the curve
            IOnCurve crv = gc.Object(0).Curve();

            if (null == crv)
            {
                return(IRhinoCommand.result.failure);
            }

            // Create an array of normalized curve parameters
            List <double> slist = new List <double>(m_max_steps);

            for (int i = 0; i < m_max_steps; i++)
            {
                double s = (double)i / ((double)m_max_steps - 1);
                slist.Add(s);
            }

            // Get the real parameters along the curve
            double[] tlist = new double[m_max_steps];
            if (!crv.GetNormalizedArcLengthPoints(slist.ToArray(), ref tlist))
            {
                return(IRhinoCommand.result.failure);
            }

            // Create the display conduit
            SampleCsAnimatorConduit conduit = new SampleCsAnimatorConduit();

            // Get points along curve
            On3dPoint        start = new On3dPoint(crv.PointAtStart());
            List <On3dPoint> plist = new List <On3dPoint>(tlist.Length);

            for (int i = 0; i < m_max_steps; i++)
            {
                On3dPoint pt = new On3dPoint(crv.PointAt(tlist[i]));
                plist.Add(pt);
            }

            // Hide objects and add them to conduit's object array
            for (int i = 0; i < go.ObjectCount(); i++)
            {
                MRhinoObjRef objref = go.Object(i);
                context.m_doc.HideObject(objref);
                conduit.m_objects.Add(objref.Object());
            }

            // Do animation...
            conduit.Enable();

            for (int i = 0; i < m_max_steps; i++)
            {
                On3dVector v = plist[i] - start;
                conduit.m_xform.Translation(v);
                context.m_doc.Redraw();
                Thread.Sleep(100);
            }

            for (int i = m_max_steps - 1; i >= 0; i--)
            {
                On3dVector v = plist[i] - start;
                conduit.m_xform.Translation(v);
                if (0 != i)
                {
                    context.m_doc.Redraw();
                    Thread.Sleep(100);
                }
            }

            conduit.Disable();

            // Show hidden objects
            for (int i = 0; i < go.ObjectCount(); i++)
            {
                MRhinoObjRef objref = go.Object(i);
                context.m_doc.ShowObject(objref);
            }

            context.m_doc.Redraw();

            return(IRhinoCommand.result.success);
        }
Пример #7
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 surface or polysurface for direction display");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            MRhinoObjRef obj_ref = go.Object(0);
            IOnBrep      brep    = obj_ref.Brep();

            if (null == brep)
            {
                return(IRhinoCommand.result.failure);
            }

            bool bIsSolid = brep.IsSolid();
            bool bFlip    = false;

            SampleCsSurfaceDirectionConduit conduit = new SampleCsSurfaceDirectionConduit();

            conduit.SetBrep(brep);
            conduit.Enable();
            context.m_doc.Redraw();

            MRhinoGetOption gf = new MRhinoGetOption();

            gf.SetCommandPrompt("Press Enter when done");
            gf.AcceptNothing();
            if (!bIsSolid)
            {
                gf.AddCommandOption(new MRhinoCommandOptionName("Flip"));
            }

            for (; ;)
            {
                IRhinoGet.result res = gf.GetOption();

                if (res == IRhinoGet.result.option)
                {
                    bFlip = !bFlip;
                    conduit.SetFlip(bFlip);
                    context.m_doc.Redraw();
                    continue;
                }

                if (res == IRhinoGet.result.nothing)
                {
                    if (!bIsSolid && bFlip)
                    {
                        OnBrep flipped_brep = new OnBrep(brep);
                        flipped_brep.Flip();
                        context.m_doc.ReplaceObject(obj_ref, flipped_brep);
                    }
                }

                break;
            }

            conduit.Disable();
            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)
        {
            // Prompt for the instance (block) name
              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Name of block to delete");
              gs.GetString();
              if (gs.CommandResult() != IRhinoCommand.result.success)
            return gs.CommandResult();

              string idef_name = gs.String().Trim();
              if (string.IsNullOrEmpty(idef_name))
            return IRhinoCommand.result.nothing;

              // Find the instance definition by name
              int idef_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name, true);
              if (idef_index < 0 || idef_index >= context.m_doc.m_instance_definition_table.InstanceDefinitionCount())
              {
            RhUtil.RhinoApp().Print(string.Format("Block definition \"{0}\" not found.\n", idef_name));
            return IRhinoCommand.result.nothing;
              }

              // Verify the instance definition can be deleted
              IRhinoInstanceDefinition idef = context.m_doc.m_instance_definition_table[idef_index];
              if (idef.IsReference())
              {
            RhUtil.RhinoApp().Print(string.Format("Block definition \"{0}\" is from a reference file.\n", idef_name));
            return IRhinoCommand.result.nothing;
              }

              // Get all of instance references
              IRhinoInstanceObject[] iref_object_list = null;
              int iref_count = idef.GetReferences(out iref_object_list);

              // Try deleting the instance references
              int num_deleted = 0;
              for (int i = 0; i < iref_count; i++)
              {
            IRhinoInstanceObject iref = iref_object_list[i];
            if (null == iref)
              continue;

            if (iref.IsDeleted() || iref.IsReference())
              continue;

            MRhinoObjRef obj_ref = new MRhinoObjRef(iref_object_list[i]);
            if (context.m_doc.DeleteObject(obj_ref, true))
              num_deleted++;
              }

              if (num_deleted > 0)
            context.m_doc.Redraw();

              RhUtil.RhinoApp().Print(string.Format("{0} \"{1}\" block(s) found, {2} deleted.\n", iref_count, idef_name, num_deleted));

              // Try deleting the instance definition
              bool iref_deleted = false;
              if (num_deleted == iref_count)
              {
            if (context.m_doc.m_instance_definition_table.DeleteInstanceDefinition(idef_index, true, false))
              iref_deleted = true;
              }

              if (iref_deleted)
            RhUtil.RhinoApp().Print(string.Format("Block definition \"{0}\" deleted.\n", idef_name));
              else
            RhUtil.RhinoApp().Print(string.Format("Block definition \"{0}\" not deleted.\n", idef_name));

              return IRhinoCommand.result.success;
        }
        ///<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 surface, polysurface, or mesh to export");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.polysrf_object | IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_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);
            }

            List <IRhinoObject> obj_list = new List <IRhinoObject>();

            obj_list.Add(obj);

            ArrayMRhinoObjectMesh mesh_list       = new ArrayMRhinoObjectMesh(obj_list.Count);
            OnMeshParameters      mesh_parameters = _mesh_parameters;
            int mesh_ui_style = !context.IsInteractive() ? 2 : _mesh_ui_style;

            IRhinoCommand.result res = RhUtil.RhinoMeshObjects(obj_list.ToArray(), ref mesh_parameters, ref mesh_ui_style, ref mesh_list);
            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
            {
                RhUtil.RhinoApp().Print("No mesh to export.\n");
                return(res);
            }

            string filename = string.Empty;

            if (context.IsInteractive())
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Title            = "Export";
                dialog.Filter           = "Geomview files|*.off";
                dialog.InitialDirectory = DirectoryManager.DefaultDirectory(DirectoryManager.FileTypes.ftExport);
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return(IRhinoCommand.result.cancel);
                }

                filename = dialog.FileName;
            }
            else
            {
                MRhinoGetString gs = new MRhinoGetString();
                gs.SetCommandPrompt("Export file name");
                gs.GetString();
                if (gs.CommandResult() != IRhinoCommand.result.success)
                {
                    return(gs.CommandResult());
                }

                filename = gs.String().Trim();
            }

            try
            {
                OnMesh mesh = mesh_list.First().GetMesh();

                int vertex_count = mesh.VertexCount();
                int face_count   = mesh.FaceCount();
                int edge_count   = mesh.Topology().m_tope.Count();

                System.IO.StreamWriter file = new System.IO.StreamWriter(filename);

                // Write out the first line of the file header
                file.WriteLine("OFF");

                // Write the header information
                file.WriteLine(string.Format("{0} {1} {2}", vertex_count, face_count, edge_count));

                file.WriteLine();

                // Write out all the vertices in order
                for (int i = 0; i < vertex_count; i++)
                {
                    On3fPoint p = mesh.m_V[i];
                    file.WriteLine(string.Format("{0} {1} {2}", p.x.ToString("F"), p.y.ToString("F"), p.z.ToString("F")));
                }

                file.WriteLine();

                // Write out all the faces
                for (int i = 0; i < face_count; i++)
                {
                    OnMeshFace f = mesh.m_F[i];
                    if (f.IsQuad())
                    {
                        file.WriteLine(string.Format("4 {0} {1} {2} {3}", f.get_vi(0), f.get_vi(1), f.get_vi(2), f.get_vi(3)));
                    }
                    else
                    {
                        file.WriteLine(string.Format("3 {0} {1} {2}", f.get_vi(0), f.get_vi(1), f.get_vi(2)));
                    }
                }

                file.Close();
            }
            catch (Exception e)
            {
                RhUtil.RhinoApp().Print(string.Format("{0}\n", e.Message));
            }

            return(IRhinoCommand.result.success);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Prompt for the instance (block) name
            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Name of block to delete");
            gs.GetString();
            if (gs.CommandResult() != IRhinoCommand.result.success)
            {
                return(gs.CommandResult());
            }

            string idef_name = gs.String().Trim();

            if (string.IsNullOrEmpty(idef_name))
            {
                return(IRhinoCommand.result.nothing);
            }

            // Find the instance definition by name
            int idef_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name, true);

            if (idef_index < 0 || idef_index >= context.m_doc.m_instance_definition_table.InstanceDefinitionCount())
            {
                RhUtil.RhinoApp().Print(string.Format("Block definition \"{0}\" not found.\n", idef_name));
                return(IRhinoCommand.result.nothing);
            }

            // Verify the instance definition can be deleted
            IRhinoInstanceDefinition idef = context.m_doc.m_instance_definition_table[idef_index];

            if (idef.IsReference())
            {
                RhUtil.RhinoApp().Print(string.Format("Block definition \"{0}\" is from a reference file.\n", idef_name));
                return(IRhinoCommand.result.nothing);
            }

            // Get all of instance references
            IRhinoInstanceObject[] iref_object_list = null;
            int iref_count = idef.GetReferences(out iref_object_list);

            // Try deleting the instance references
            int num_deleted = 0;

            for (int i = 0; i < iref_count; i++)
            {
                IRhinoInstanceObject iref = iref_object_list[i];
                if (null == iref)
                {
                    continue;
                }

                if (iref.IsDeleted() || iref.IsReference())
                {
                    continue;
                }

                MRhinoObjRef obj_ref = new MRhinoObjRef(iref_object_list[i]);
                if (context.m_doc.DeleteObject(obj_ref, true))
                {
                    num_deleted++;
                }
            }

            if (num_deleted > 0)
            {
                context.m_doc.Redraw();
            }

            RhUtil.RhinoApp().Print(string.Format("{0} \"{1}\" block(s) found, {2} deleted.\n", iref_count, idef_name, num_deleted));

            // Try deleting the instance definition
            bool iref_deleted = false;

            if (num_deleted == iref_count)
            {
                if (context.m_doc.m_instance_definition_table.DeleteInstanceDefinition(idef_index, true, false))
                {
                    iref_deleted = true;
                }
            }

            if (iref_deleted)
            {
                RhUtil.RhinoApp().Print(string.Format("Block definition \"{0}\" deleted.\n", idef_name));
            }
            else
            {
                RhUtil.RhinoApp().Print(string.Format("Block definition \"{0}\" not deleted.\n", idef_name));
            }

            return(IRhinoCommand.result.success);
        }