Good afternoon sirs!
I’m currently experimenting on how I can exchange information from rhino to python and the other way arround. So I was testing how to write a block instance into a 3dm file.
Here is what I coded so far:
success, block = check_block_in_file3dm(True, block_name, rhino_file3dm) rhino_layer = Rhino.DocObjects.Layer() rhino_layer.Name = 'objects' rhino_layer.Color = System.Drawing.Color.FromArgb(0, 227, 144) file3dm.AllLayers.Add(rhino_layer) rhino_object_attributes = Rhino.DocObjects.ObjectAttributes() rhino_object_attributes.LayerIndex = rhino_layer.Index rhino_object_attributes.Name = block_name xform = rg.Transform() xform.M03 = 1 xform.M13 = 1 xform.M23 = 0 file3dm.Objects.AddInstanceObject(block.Index, xform, rhino_object_attributes) file3dm.Write("test_exports/test-export-to-rhino.3dm", 6)
Where check_block_in_file3dm(True, block_name, rhino_file3dm) is:
def check_block_in_file3dm(prev_success: bool, block_name: str, file3dm): success = False block = None all_blocks = file3dm.AllInstanceDefinitions for b in all_blocks: if b.Name == block_name: success = True block = b return(success, block)
The ‘block’ variable used is a valid InstanceDefinitionGeometry and the code runs without erros, but the 3dm file created has no objects in it. Any ideia on where the problem is?
I guess that I still don’t understand how to add InstanceObjects into a document.