Hello,
I’m trying to save Blocks and BlocksInstances from a .NET application. I’ve managed to add my InstanceDefinitionGeometry in the File.AllInstanceDefinitions collection. But now I would like to save the actual instances. With most object types there’s a dedicated File3dm.Objects.AddXXX, but I don’t see one for InstanceReferenceGeometry. Perhaps i’m not looking at the right place?
I’m using the latest prerelease Rhino3dmIO.Desktop version 7.0.18072.3575-wip
Thanks for your help.
I mean not the InstanceDefinitionGeometry with actual geometry. But the actual instance. Which generally is only a transformation. I think you call them InstanceReferenceGeometry.
Here’s some additional information to better describe my problem. Please see attached 3dm file created with Rhino 5. It contains 1 block (a square polyline) and 4 instances.
When reading the file, I can iterate the File3dm.AllInstanceDefinitions.GetObjectIds to get the guids of the geometry defining the block. Then I retrieve the objects from the File3dm.Objects by checking the File3dm.File3dmObjects.Attributes.ObjectId. With the attached sample file, it would retrieve only one Polyline.
Now I have my Block defined, I need the instances. I can iterate File3dm.File3dmObjects and get the InstanceReferenceGeometry objects which are basically a transformation and a parent guid pointing to the InstanceDefinitionGeometry.
I can successfully read blocks and instances from the 3dm files. Now my problem, is when I want to save them.
Saving the definitions:
I can create InstanceDefinitionGeometry (specifying name) and add them to the File3dm.AllInstancesDefinitions collection, retrieve their guid (I’d be great if the Add method would return the guid of the newly added def). Now somehow, I need to add the geometry defining the block in the File3dm.File3dmObjects collection and provide the parent InstanceDefinitionGeometry id. I thought perhaps there was a ObjectAttributes subclass, but couldn’t find any. How should I add the geometry defining a block to the File3dmObjects collection?
Saving the instances:
With all other object types there is a file3dm.Objects.AddXXX(geometryBase, attributes). I can create my geometryBase like this: new InstanceRefenceGeometry(parentGuid, transformation), I also have the attributes… I just don’t see a method to add them to the file3dm.Objects collection. Any clue?
Unfortunately no. The File3dmObjectTable.Add method only takes a File3dmObject as parameter. The only File3dmObject constructor supports a Guid and another File3dm and it’s attributes and geometry are read-only. I’m guessing it is for external block references.