How can I replace a nested "Instance Definition" Object in C#?

I have library of blocks and inside my blocks I have others (a few hundred).

I’d like to add something to a C# script I’m already running on the Instance Definitions, to swap out the nested blocks with other nested blocks. Unconventional, but there is no other work-around because I’m pulling the blocks from an external file and that’s by design.

Right now I am able to find the object I want no problem ( InstanceDefinition.Object(i) or just the var “obj”).

var libraryInstanceDefinition = libraryDoc.InstanceDefinitions.Find(libDefName);
var obj = libraryInstanceDefinition.Object(i);

I know the block name for my chosen block for replacement and want to do something like this:

obj = (rhinodoc.InstanceDefinitions.Find(theDesiredBlock.Name) as RhinoObject);

But I can’t think of what I’d need to do to cast it corrrectly. Anybody have any thoughts?

Hi @wortley.jb,

To modify the geometry used by an instance definition, you must use InstanceDefinitionTable.ModifyGeometry.

Does this help?

– Dale

Thanks Dale,

I haven’t had time to work on this again, but will give that a try next!