Пример #1
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MArgsRhinoGetCircle args   = new MArgsRhinoGetCircle();
            OnCircle            circle = new OnCircle();

            IRhinoCommand.result rc = RhUtil.RhinoGetCircle(args, ref circle);
            if (rc != IRhinoCommand.result.success)
            {
                return(rc);
            }

            SampleCsDrawCircleConduit conduit = new SampleCsDrawCircleConduit(circle);

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

            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Press <Enter> to continue");
            gs.AcceptNothing();
            gs.GetString();

            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)
        {
            MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select mesh");
              go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.mesh_object);
              go.GetObjects(1, 1);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              IRhinoMeshObject mesh_object = MRhinoMeshObject.ConstCast(go.Object(0).Object());
              if (null == mesh_object)
            return IRhinoCommand.result.failure;

              SampleCsColoredMeshConduit conduit = new SampleCsColoredMeshConduit(mesh_object.m_runtime_object_serial_number);
              conduit.Enable();
              context.m_doc.Regen();

              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Press <Enter> to continue");
              gs.AcceptNothing();
              gs.GetString();

              conduit.Disable();
              context.m_doc.Regen();

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

            IRhinoMeshObject mesh_object = MRhinoMeshObject.ConstCast(go.Object(0).Object());

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

            SampleCsColoredMeshConduit conduit = new SampleCsColoredMeshConduit(mesh_object.m_runtime_object_serial_number);

            conduit.Enable();
            context.m_doc.Regen();

            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Press <Enter> to continue");
            gs.AcceptNothing();
            gs.GetString();

            conduit.Disable();
            context.m_doc.Regen();

            return(IRhinoCommand.result.success);
        }
Пример #4
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);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            OnLine  line  = new OnLine();
            OnPlane plane = new OnPlane();

            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Start of line");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            line.from = gp.Point();
            plane     = new OnPlane(RhUtil.RhinoActiveCPlane());
            plane.SetOrigin(line.from);

            gp.SetCommandPrompt("End of line");
            gp.Constrain(plane);
            gp.SetBasePoint(line.from);
            gp.DrawLineFromPoint(line.from, true);
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            line.to = plane.ClosestPointTo(gp.Point());
            if (!line.IsValid())
            {
                return(IRhinoCommand.result.nothing);
            }

            SampleCsDrawArrowheadConduit conduit = new SampleCsDrawArrowheadConduit(plane, line, 1.0);

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

            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Press <Enter> to continue");
            gs.AcceptNothing();
            gs.GetString();

            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)
        {
            On3dPoint center = new On3dPoint(OnUtil.On_origin);
              OnSphere sphere = new OnSphere(center, 5.0);
              OnMesh mesh = RhUtil.RhinoMeshSphere(sphere, 10, 10);
              MRhinoMeshObject mesh_obj = context.m_doc.AddMeshObject(mesh);
              context.m_doc.Redraw();

              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Press <Enter> to continue");
              gs.AcceptNothing();
              gs.GetString();

              context.m_doc.DeleteObject(new MRhinoObjRef(mesh_obj));
              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)
        {
            On3dPoint        center   = new On3dPoint(OnUtil.On_origin);
            OnSphere         sphere   = new OnSphere(center, 5.0);
            OnMesh           mesh     = RhUtil.RhinoMeshSphere(sphere, 10, 10);
            MRhinoMeshObject mesh_obj = context.m_doc.AddMeshObject(mesh);

            context.m_doc.Redraw();

            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Press <Enter> to continue");
            gs.AcceptNothing();
            gs.GetString();

            context.m_doc.DeleteObject(new MRhinoObjRef(mesh_obj));
            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)
        {
            OnLine line = new OnLine();
              OnPlane plane = new OnPlane();

              MRhinoGetPoint gp = new MRhinoGetPoint();
              gp.SetCommandPrompt("Start of line");
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              line.from = gp.Point();
              plane = new OnPlane(RhUtil.RhinoActiveCPlane());
              plane.SetOrigin(line.from);

              gp.SetCommandPrompt("End of line");
              gp.Constrain(plane);
              gp.SetBasePoint(line.from);
              gp.DrawLineFromPoint(line.from, true);
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              line.to = plane.ClosestPointTo(gp.Point());
              if (!line.IsValid())
            return IRhinoCommand.result.nothing;

              SampleCsDrawArrowheadConduit conduit = new SampleCsDrawArrowheadConduit(plane, line, 1.0);
              conduit.Enable();
              context.m_doc.Redraw();

              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Press <Enter> to continue");
              gs.AcceptNothing();
              gs.GetString();

              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)
        {
            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)
        {
            MArgsRhinoGetCircle args = new MArgsRhinoGetCircle();
              OnCircle circle = new OnCircle();
              IRhinoCommand.result rc = RhUtil.RhinoGetCircle(args, ref circle);
              if (rc != IRhinoCommand.result.success)
            return rc;

              SampleCsDrawCircleConduit conduit = new SampleCsDrawCircleConduit(circle);
              conduit.Enable();
              context.m_doc.Redraw();

              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Press <Enter> to continue");
              gs.AcceptNothing();
              gs.GetString();

              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);
        }
Пример #13
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Step 1, select objects to include in the instance definition
              MRhinoGetObject go = new MRhinoGetObject();
              go.SetCommandPrompt("Select objects to define block");
              go.EnableReferenceObjectSelect(false);
              go.EnableSubObjectSelect(false);
              go.EnableGroupSelect(true);
              // Phantoms, grips, lights, etc., cannot be in instance definitions.
              uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object |
                                              IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object |
                                              IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object
                                              );
              uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object;
              go.SetGeometryFilter(geometry_filter);
              go.GetObjects(1, 0);
              if (go.CommandResult() != IRhinoCommand.result.success)
            return go.CommandResult();

              // Step 2, select base point
              MRhinoGetPoint gp = new MRhinoGetPoint();
              gp.SetCommandPrompt("Block base point");
              gp.GetPoint();
              if (gp.CommandResult() != IRhinoCommand.result.success)
            return gp.CommandResult();

              On3dPoint base_point = gp.Point();

              // Step 3, get instance definition name
              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Block definition name");
              gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc));
              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;

              // Step 4, verify objects
              int found_index = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name);
              List<IRhinoObject> objects = new List<IRhinoObject>();

              bool bQuietly = context.IsInteractive() ? false : true;

              for (int i = 0; i < go.ObjectCount(); i++)
              {
            IRhinoObject obj = go.Object(i).Object();
            if (obj == null)
              continue;

            // Probably don't need to do this...
            if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType()))
              continue;

            if (obj.ObjectType() == IOn.object_type.instance_reference)
            {
              IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj);
              if (iref_obj != null)
              {
            if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0)
            {
              if (!bQuietly)
                RhUtil.RhinoApp().Print("Unable to create block.\n");
              return IRhinoCommand.result.failure;
            }
              }
            }
            objects.Add(obj);
              }

              // Step 5, create instance definition
              OnInstanceDefinition idef = new OnInstanceDefinition();
              idef.SetName(idef_name);

              int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly);
              if (idef_index < 0)
            return IRhinoCommand.result.failure;

              // Step 6, create the instance reference
              OnXform xform = new OnXform();
              xform.Translation(base_point - new On3dPoint(OnUtil.On_origin));
              IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform);
              if (inst_obj != null)
              {
            inst_obj.Select(true);
              }
              else
              {
            if (!bQuietly)
              RhUtil.RhinoApp().Print("Error creating block.\n");
            return IRhinoCommand.result.failure;
              }

              // Step 7, delete existing geometry
              for (int i = 0; i < objects.Count; i++)
            context.m_doc.DeleteObject(new MRhinoObjRef(objects[i]));

              context.m_doc.Redraw();

              return IRhinoCommand.result.success;
        }
Пример #14
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Step 1, select objects to include in the instance definition
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select objects to define block");
            go.EnableReferenceObjectSelect(false);
            go.EnableSubObjectSelect(false);
            go.EnableGroupSelect(true);
            // Phantoms, grips, lights, etc., cannot be in instance definitions.
            uint forbidden_geometry_filter = (uint)(IRhinoGetObject.GEOMETRY_TYPE_FILTER.light_object |
                                                    IRhinoGetObject.GEOMETRY_TYPE_FILTER.grip_object |
                                                    IRhinoGetObject.GEOMETRY_TYPE_FILTER.phantom_object
                                                    );
            uint geometry_filter = forbidden_geometry_filter ^ (uint)IRhinoGetObject.GEOMETRY_TYPE_FILTER.any_object;

            go.SetGeometryFilter(geometry_filter);
            go.GetObjects(1, 0);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Step 2, select base point
            MRhinoGetPoint gp = new MRhinoGetPoint();

            gp.SetCommandPrompt("Block base point");
            gp.GetPoint();
            if (gp.CommandResult() != IRhinoCommand.result.success)
            {
                return(gp.CommandResult());
            }

            On3dPoint base_point = gp.Point();

            // Step 3, get instance definition name
            MRhinoGetString gs = new MRhinoGetString();

            gs.SetCommandPrompt("Block definition name");
            gs.SetDefaultString(GetUnusedInstanceDefinitionName(context.m_doc));
            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);
            }

            // Step 4, verify objects
            int found_index             = context.m_doc.m_instance_definition_table.FindInstanceDefinition(idef_name);
            List <IRhinoObject> objects = new List <IRhinoObject>();

            bool bQuietly = context.IsInteractive() ? false : true;

            for (int i = 0; i < go.ObjectCount(); i++)
            {
                IRhinoObject obj = go.Object(i).Object();
                if (obj == null)
                {
                    continue;
                }

                // Probably don't need to do this...
                if (0 != (forbidden_geometry_filter & (uint)obj.ObjectType()))
                {
                    continue;
                }

                if (obj.ObjectType() == IOn.object_type.instance_reference)
                {
                    IRhinoInstanceObject iref_obj = MRhinoInstanceObject.ConstCast(obj);
                    if (iref_obj != null)
                    {
                        if (found_index >= 0 && iref_obj.UsesDefinition(found_index) > 0)
                        {
                            if (!bQuietly)
                            {
                                RhUtil.RhinoApp().Print("Unable to create block.\n");
                            }
                            return(IRhinoCommand.result.failure);
                        }
                    }
                }
                objects.Add(obj);
            }

            // Step 5, create instance definition
            OnInstanceDefinition idef = new OnInstanceDefinition();

            idef.SetName(idef_name);

            int idef_index = CreateInstanceDefinition(context.m_doc, idef, base_point, objects, bQuietly);

            if (idef_index < 0)
            {
                return(IRhinoCommand.result.failure);
            }

            // Step 6, create the instance reference
            OnXform xform = new OnXform();

            xform.Translation(base_point - new On3dPoint(OnUtil.On_origin));
            IRhinoInstanceObject inst_obj = context.m_doc.m_instance_definition_table.CreateInstanceObject(idef_index, xform);

            if (inst_obj != null)
            {
                inst_obj.Select(true);
            }
            else
            {
                if (!bQuietly)
                {
                    RhUtil.RhinoApp().Print("Error creating block.\n");
                }
                return(IRhinoCommand.result.failure);
            }

            // Step 7, delete existing geometry
            for (int i = 0; i < objects.Count; i++)
            {
                context.m_doc.DeleteObject(new MRhinoObjRef(objects[i]));
            }

            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)
        {
            // Get the name of the instance definition to rename
            MRhinoGetString gs = new MRhinoGetString();

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

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

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

            // Verify instance definition exists
            MRhinoInstanceDefinitionTable idef_table = context.m_doc.m_instance_definition_table;
            int idef_index = idef_table.FindInstanceDefinition(idef_name);

            if (idef_index < 0)
            {
                RhUtil.RhinoApp().Print(string.Format("Block \"{0}\" not found.\n", idef_name));
                return(IRhinoCommand.result.nothing);
            }

            // Verify instance definition is rename-able
            IRhinoInstanceDefinition idef = idef_table[idef_index];

            if (idef.IsDeleted() || idef.IsReference())
            {
                RhUtil.RhinoApp().Print(string.Format("Unable to rename block \"{0}\".\n", idef_name));
                return(IRhinoCommand.result.nothing);
            }

            // Get the new instance definition name
            gs.SetCommandPrompt("New block name");
            gs.GetString();
            if (gs.CommandResult() != IRhinoCommand.result.success)
            {
                return(gs.CommandResult());
            }

            // Validate string
            string new_idef_name = gs.String().Trim();

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

            // Verify the new instance definition name is not already in use
            int new_idef_index = idef_table.FindInstanceDefinition(new_idef_name);

            if (new_idef_index >= 0 && new_idef_index < idef_table.InstanceDefinitionCount())
            {
                if (!idef_table[new_idef_index].IsDeleted())
                {
                    RhUtil.RhinoApp().Print(string.Format("Block \"{0}\" already exists.\n", new_idef_name));
                    return(IRhinoCommand.result.nothing);
                }
            }

            // Make a copy of the instance definition object
            OnInstanceDefinition new_idef = new OnInstanceDefinition(idef);

            // Rename the copy
            new_idef.SetName(new_idef_name);

            // Modify the existing instance definition with our copy
            if (idef_table.ModifyInstanceDefinition(new_idef, idef_index, (uint)idef_settings.idef_name_setting, false))
            {
                return(IRhinoCommand.result.success);
            }

            return(IRhinoCommand.result.failure);
        }
        ///<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)
        {
            // Get the name of the instance definition to rename
              MRhinoGetString gs = new MRhinoGetString();
              gs.SetCommandPrompt("Name of block to rename");
              gs.GetString();
              if (gs.CommandResult() != IRhinoCommand.result.success)
            return gs.CommandResult();

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

              // Verify instance definition exists
              MRhinoInstanceDefinitionTable idef_table = context.m_doc.m_instance_definition_table;
              int idef_index = idef_table.FindInstanceDefinition(idef_name);
              if (idef_index < 0)
              {
            RhUtil.RhinoApp().Print(string.Format("Block \"{0}\" not found.\n", idef_name));
            return IRhinoCommand.result.nothing;
              }

              // Verify instance definition is rename-able
              IRhinoInstanceDefinition idef = idef_table[idef_index];
              if (idef.IsDeleted() || idef.IsReference())
              {
            RhUtil.RhinoApp().Print(string.Format("Unable to rename block \"{0}\".\n", idef_name));
            return IRhinoCommand.result.nothing;
              }

              // Get the new instance definition name
              gs.SetCommandPrompt("New block name");
              gs.GetString();
              if (gs.CommandResult() != IRhinoCommand.result.success)
            return gs.CommandResult();

              // Validate string
              string new_idef_name = gs.String().Trim();
              if (string.IsNullOrEmpty(new_idef_name))
            return IRhinoCommand.result.nothing;

              // Verify the new instance definition name is not already in use
              int new_idef_index = idef_table.FindInstanceDefinition(new_idef_name);
              if (new_idef_index >= 0 && new_idef_index < idef_table.InstanceDefinitionCount())
              {
            if (!idef_table[new_idef_index].IsDeleted())
            {
              RhUtil.RhinoApp().Print(string.Format("Block \"{0}\" already exists.\n", new_idef_name));
              return IRhinoCommand.result.nothing;
            }
              }

              // Make a copy of the instance definition object
              OnInstanceDefinition new_idef = new OnInstanceDefinition(idef);

              // Rename the copy
              new_idef.SetName(new_idef_name);

              // Modify the existing instance definition with our copy
              if (idef_table.ModifyInstanceDefinition(new_idef, idef_index, (uint)idef_settings.idef_name_setting, false))
            return IRhinoCommand.result.success;

              return IRhinoCommand.result.failure;
        }