How can you set the Render material to a BREP using the rhino3dm library?
import rhino3dm
file_path = r'C:\Users\dande\Documents\GitHub\project-template\Rhino Template\CPI.TEMPLATE.R4.3dm'
model = rhino3dm.File3dm.Read(file_path)
#is this the best way to get a layer index for a given layer name?
for layer in model.Layers:
#print(layer.Name)
if layer.Name == "LOD 300":
lod_300_index = layer.Index
#how to find the material index for a given render material name?
for material in model.Materials:
print(material.Name)
print(material.RenderMaterialInstanceId)
if material.Name == "STEEL_PRIMED":
print("Steel found")
#steel_index = material.Index ---- this doesn't work, so how do I get the material index given a RENDER material name?
else:
steel_index = 2 #a dummy index
box1 = rhino3dm.BoundingBox(rhino3dm.Point3d( 0,0,0 ), rhino3dm.Point3d( 4,5,0.75))
geometry = (box1.ToBrep())
attr = rhino3dm.ObjectAttributes()
attr.Name = "Box"
attr.LayerIndex = lod_300_index
attr.MaterialIndex = 2 #this a dummy index, but it doesn't seem to work, does the object material source need to be changed?
model.Objects.AddBrep(geometry,attr)
write = model.Write('plate_tests.3dm',7)