///<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);
        }