Setting attributes of new objects

Hi,

If I create a new curve or something from RhinoCommon(Python,) do I have to do something to it or actually add it to the document to be able to set/get the .Attributes object? I’ve got a curve I’m trying to set the layer and name on before adding it to the document and it’s saying the object has no attribute ‘Attributes’?

EDIT: got it, the “object attributes” object is separate from the curve, I pass both when I actually add the curve to the doc.

Thanks,
Jim

Hi Jim,

I have been able to create a default set of attributes so I can add/bake text to rhino in python from grasshopper but still a little lost on how I edit these attributes before I assign them.

Could you maybe share either your code or an example of what you did to be able to set the Layer etc?

Cheers
Matt

Hi @mattgaydon, you can change the attributes listed here before assigning them, eg.

# create attributes
attr = Rhino.DocObjects.ObjectAttributes()
attr.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject
attr.ObjectColor = System.Drawing.Color.Red
# add objects with attributes
scriptcontext.doc.Objects.AddCurve(curve, attr)

If you know the destination layer index, you could use this:

attr.LayerIndex = scriptcontext.doc.Layers.CurrentLayerIndex

_
c.

Thanks, Clement, I had Rhino.DocObjects.ObjectAttributes() but not worked out how to change them.

Also found this on my travels too which was helpful. Shame it uses Rhinoscript to Add a layer to the doc and not rhino common. http://cu.t-ads.org/tips-script-context-in-gh-python/