File3dm InstanceReferenceGeometry

Hi,

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
F=r.FileIO.File3dm.Read(x)
a=[i for i in F.Objects]
b=F.AllInstanceDefinitions
c=[i.Geometry for i in a]
il=[]
for i in c:
    if 'Instance' in str(i):
        il.append(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.

SampleCsExplodeBlock.cs

– 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

Hi Dale, how difficult would it be to make this into a a Grasshopper c# component? I got a whole lot of InstanceRefereenceGeometry that I cannot use…

image

Grasshopper for the Rhino 8 WIP supports blocks - you might have a look.

– Dale

1 Like