Click or drag to resize

InstanceDefinitionIsReference Property

An object from a work session reference model is reference a reference object and cannot be modified. An object is a reference object if, and only if, it is on a reference layer.

Namespace:  Rhino.DocObjects
Assembly:  RhinoCommon (in RhinoCommon.dll)
Since: 5.0
Syntax
public override bool IsReference { get; }

Property Value

Type: Boolean
Examples
using Rhino;
using Rhino.Input;
using Rhino.Commands;

namespace examples_cs
{
  public class RenameBlockCommand : Command
  {
    public override string EnglishName { get { return "csRenameBlock"; } }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      // Get the name of the insance definition to rename
      var instance_definition_name = "";
      var rc = RhinoGet.GetString("Name of block to rename", true, ref instance_definition_name);
      if (rc != Result.Success)
        return rc;
      if (string.IsNullOrWhiteSpace(instance_definition_name))
        return Result.Nothing;

      // Verify instance definition exists
      var instance_definition = doc.InstanceDefinitions.Find(instance_definition_name, true);
      if (instance_definition == null) {
        RhinoApp.WriteLine("Block '{0}' not found.", instance_definition_name);
        return Result.Nothing;
      }

      // Verify instance definition is rename-able
      if (instance_definition.IsDeleted || instance_definition.IsReference) {
        RhinoApp.WriteLine("Unable to rename block '{0}'.", instance_definition_name);
        return Result.Nothing;
      }

      // Get the new instance definition name
      string instance_definition_new_name = "";
      rc = RhinoGet.GetString("Name of block to rename", true, ref instance_definition_new_name);
      if (rc != Result.Success)
        return rc;
      if (string.IsNullOrWhiteSpace(instance_definition_new_name))
        return Result.Nothing;

      // Verify the new instance definition name is not already in use
      var existing_instance_definition = doc.InstanceDefinitions.Find(instance_definition_new_name, true);
      if (existing_instance_definition != null && !existing_instance_definition.IsDeleted) {
        RhinoApp.WriteLine("Block '{0}' already exists.", existing_instance_definition);
        return Result.Nothing;
      }

      // change the block name
      if (!doc.InstanceDefinitions.Modify(instance_definition.Index, instance_definition_new_name, instance_definition.Description, true)) {
        RhinoApp.WriteLine("Could not rename {0} to {1}", instance_definition.Name, instance_definition_new_name);
        return Result.Failure;
      }

      return Result.Success;
    }
  }
}
Python
import rhinoscriptsyntax as rs
from scriptcontext import doc

def Rename():
    blockName = rs.GetString("block to rename")
    instanceDefinition = doc.InstanceDefinitions.Find(blockName, True)
    if not instanceDefinition: 
        print "{0} block does not exist".format(blockName)
        return

    newName = rs.GetString("new name")
    instanceDefinition = doc.InstanceDefinitions.Find(newName, True)
    if instanceDefinition: 
        print "the name '{0}' is already taken by another block".format(newName)
        return

    rs.RenameBlock(blockName, newName)

if __name__ == "__main__":
    Rename()
See Also