InstanceDefinition & nested blocks

Hi there,

Just starting to use Rhino3d .net package to parse 3dm files. Later, my goal will be to develop a Rhino plugin (with Rhino.Common) to get the tree structure of the active model. I don’t know if a such plugin exists.

Rhino3d .net package works quite fine, but I still encounter some problems :

  1. I can’t see how to match an object (in AllObjects) with his block InstanceDefinition. Each object.Attributes has a bool IsInstanceDefinitionObject, but i can’t see any InstanceDefinitionIndex. The goal is to “assemble” objects by block.

  2. Moreover i can’t see how to explore blocks recursively when it comes with nested blocks. The Instance definition object need to have a InstanceDefinitionIndex to be able to rebuild the hiearchy.

  3. I can’t see how to get the xform transformation of an InstanceDefinition. I can see xform object when debugging, but the attribute is not accessible !

  4. How to get the group index of an object ? I can see Attributes.GetGroupList(), why a list ? A solid can be in more than one group ?

  5. group.Name does’t not match the right name set in Rhino, I always get “GroupXX”. I figure out the group name is on the solid. The name of the group is on its objects, so that the real object’s name is replaced by the group’s name.

  6. How to deal with groups inside blocks…?

    Thanks for helping.

Indeed, an object can belong to multiple groups

You need to iterate over the objects in a definition and check their type. Recurse when you find an object that is another instance definition.

See this example of how to do that with RhinoCommon. I imagine that rhino3dm works close the same way.

Hi @nathanletwory

Thank you for your answer.

Unfortunatly Rhino3dm works in a different than Rhino.Common. A 3dm file is loaded as a memory object using var doc = File3dm.Read(filepath), so that it’s not possible to execute commands, one can only explore the doc object.

Indeed, but the sample does show you how to investigate block instamces, their definitions and how to do so with nested block definitions.

1 Like

It is best to walk through the instance definition table to get lists of objects that are in the instance definitions. This is what Nathan is showing in his sample

1 Like

Now, i can retrieve everything when using Rhino3dm in good way.

1 - Except, AllGroups doesn’t contained the groups of a block, so that i can’t make the matching through Attributes.GetGroupList of an InstanceReferenceGeometry.

2 - Moreover, something strange, much more about Rhino, the material of a layer in a block seems to not be transfered (either linked or incrusted).

Thanks for helping.