Exception has occurred: TypeError
AddLayer(): incompatible function arguments. The following argument types are supported:
1. (self: rhino3dm._rhino3dm.File3dmLayerTable, name: str, color: tuple) → int
As for adding a layer into the “model”. What you call model is what mcneel calls the active document. First you need to target the active document then its layer table inside that.
There may be better ways about it but here is how I do it.
import Rhino as R
import rhinoscriptsyntax as rs
import System
doc = R.RhinoDoc.ActiveDoc
layer_table = doc.Layers
blue = System.Drawing.Color.Blue
layer_table.Add("Test Layer",blue)
import rhino3dm
import random
model = rhino3dm.File3dm()
color = (255, 0, 0, 255) #RGBA
model.Layers.AddLayer("Red", color)
for i in range(20):
pt = rhino3dm.Point3d(random.uniform(-10,10), random.uniform(-10,10), 0)
model.Objects.AddPoint(pt)
circle = rhino3dm.Circle(pt, random.uniform(1,4))
model.Objects.AddCircle(circle)
model.Write("Circles.3dm")
Thank you all for the responses, and Dale in particular!
I’ve expanded Dale’s code. I’m now defining two different layers and randomly assigning the circles to either layer. This is exactly the functionality I was seeking! Thank you!
import rhino3dm
import random
model = rhino3dm.File3dm()
color = (255, 0, 0, 255) #RGBA
model.Layers.AddLayer("Red", color)
color2 = (0, 0, 255, 255) #RGBA
model.Layers.AddLayer("Blue", color2)
for i in range(20):
objattributes = rhino3dm.ObjectAttributes()
objattributes.LayerIndex = random.randrange(2)
pt = rhino3dm.Point3d(random.uniform(-10,10), random.uniform(-10,10), 0)
model.Objects.AddPoint(pt)
circle = rhino3dm.Circle(pt, random.uniform(1,4))
model.Objects.AddCircle(circle, objattributes)
model.Write("Circles.3dm")
Is the syntax for defining block instances (and then assigning objects to those block instances) similar?