Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4159

How to modify a block definition in python?

$
0
0

I want to get an object from a file and add it to the block definitions (I figured out how to do this). Then, I would like to add other obects to the block definition. This is what I’ve got so far (for an example). When I run it, I get an error saying that Breps do not have a Geometry attribute.

#! python3
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino.Geometry as rg
import Rhino
from Rhino import RhinoDoc as rdoc

block_name = rdoc.ActiveDoc.InstanceDefinitions.GetUnusedInstanceDefinitionName("torus")
path = "C:\\Users\\Owner\\Desktop\\torus.3dm"

torus_file = Rhino.FileIO.File3dm().Read(path)
torus = torus_file.Objects.FindByLayer('Default')[0]
index = rdoc.ActiveDoc.InstanceDefinitions.Add(block_name, "", rg.Plane.WorldXY.Origin, torus.Geometry, torus.Attributes)

sphere = rg.Sphere(rg.Plane.WorldXY.Origin, 1.2).ToBrep()
rdoc.ActiveDoc.InstanceDefinitions.ModifyGeometry(index, sphere.Geometry, sphere.Attributes)

# I would like this to have the torus and the sphere combined
sc.doc.Objects.Add(torus.Geometry, torus.Attributes)





insert_block_test.py (801 Bytes)
torus.3dm (55.0 KB)

7 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 4159

Trending Articles