File3dm InstanceReferenceGeometry


I am trying to get the Block Instances and transform them into their original positions by reading the File3dm that contains those Block Instances. However I could only get the outputs as seen below.

This is my code:

import Rhino as r
a=[i for i in F.Objects]
c=[i.Geometry for i in a]
for i in c:
    if 'Instance' in str(i):
d=[i.Xform for i in il]

And this is the file that I want to read, that contains the Blocks.

Blocks.3dm (33.3 KB)

Thanks a lot in advance.

Hi @hbe,

If you open your file in Rhino and the run BlockManager, you’ll see that the file contains seven instance definitions. Four of the instance definitions are oddly nested. That is, the parent instance definition does not contain any objects other than a instance object. Basically you have some unnecessary nesting.

Instance definitions are always oriented about the world origin, and they have no transformation associated with them.

Instance objects are “instances” of an instance definition. Instance objects have no real geometry - that only reference the definition. They do have a transformation.

If you close the BlockManager and run SelAll, four instance objects will be selected. Are these the “objects” you are trying to import?

If so, then rather than iterating File3dm.AllInstanceDefinitions, you’ll need to iterate File3dm.Objects and look for objects of type InstanceObject. When found, determine it’s instance definition, get the definition’s geometry, make a copy, and transform the copied geometry using the instance object’s transformation.

Hope this helps.

– Dale

1 Like

Hi @hbe,

If you run into instance definitions that contains instance references as geometry (e.g. nested instances), then you’ll need to recurse the instance definition until you get to the bottom.

Here is a RhinoCommon, C# plug-in command sample that does just that. Perhaps you can adapt this code to what you need.


– Dale

Hi @hbe,

The example digs out the instance definition geometry, and does so recursively.

The InstanceObject.Explode basically does what th Explode command does when you pick an instance reference. This is not recursive, so you can end up with additional instance references. Plus, this returns Rhino document objects, not geometry.

– Dale