How to best transform InstanceObjects inside InstanceDefinitions?


I need to transform InstanceObjects. I can do this with
ObjectTable.Transform(obj, xForm, deleteOriginal: true), see ObjectTable.Transform Method (RhinoObject, Transform, Boolean)

But that doesn’t work if the InstanceObject is part of another InstanceDefinition (obj.IsInstanceDefinitionGeometry is true).

The only way to transform such an InstanceObject, that I’ve found is the InstanceDefinitionTable.ModifyGeometry method, see InstanceDefinitionTable.ModifyGeometry Method (Int32, IEnumerable(GeometryBase), IEnumerable(ObjectAttributes))

var oldObjects = definition.GetObjects();
var geometries = oldObjects.Select(x => x.Geometry);
var attributes = oldObjects.Select(x => x.Attributes);
// replace the object to transform with a new InstanceReferenceGeometry with new transform
InstanceDefinitionTable.ModifyGeometry(definition.Index, geometries, attributes);

This does work, but it changes the Id of all objects belonging to the InstanceDefinition. When using the BlockEdit command manually, the Ids stay the same. I’d really love to not change all those Ids. What can I do to keep the Ids? Are there totally different ways to transform a nested InstanceObject that I haven’t thought about yet?

Thanks for helping out,


I am facing the same problem now. Would like to ask if there’s a better way we can tranform InstanceObject? Thanks