Name created object by its path

Dear Rhino Users and Developers,

how can I add name to recently created object. I have string of its path, which I would like to put as its name.

obj=scriptcontext.doc.Objects.AddPointCloud(…)

Thank you for any help.

Hi @mlukasz87,

You can do that using the ObjectAttributes Class

# myPointCloud is a pointCloud defined elsewhere
# myName is a string of the name you want, defined elsewhere

import Rhino
import scriptcontext as sc

attributes = Rhino.DocObjects.ObjectAttributes()
attributes.Name = myName

sc.doc.Objects.AddPointCloud(myPointCloud, attributes)

sc.doc.Views.Redraw()
1 Like

Hi @lando.schumpich ,
I didn’t mentioned that I am using Rhino 5. I have found that equivalent for Rhino 6 class ObjectAttributes could be RhinoObject, but Rhino is not allowing me to use:

attributes=Rhino.DocObjects.RhinoObject()

I get this message while debugging:

Cannot create instances of RhinoObject because it has no public constructors

I could instead try to use this after creation of point cloud

rhinoscriptsyntax.ObjectName(strID,myName)

but I don’t know how to get its ID?

Could you provide some advice how to succed?

Ok I have found that I missed the most obvious. In fact
obj=scriptcontext.doc.Objects.AddPointCloud(myPointCloud)
is storing ID.

This worked for me. Makes job done and I am ok with that. Anyway I appreciate your help @lando.schumpich.

obj=scriptcontext.doc.Objects.AddPointCloud(myPointCloud)
rs.ObjectName(obj,myName)
scriptcontext.doc.Views.Redraw()

Dunno, this seems to work in Rhino 5:

import scriptcontext as sc
import Rhino


pc=Rhino.Geometry.PointCloud()
for i in range(5):
    for j in range(5):
        for k in range(5):
            pc.Add(Rhino.Geometry.Point3d(i,j,k))

attrs=Rhino.DocObjects.ObjectAttributes()
attrs.Name="MyPointCloud"

pc_id=sc.doc.Objects.AddPointCloud(pc,attrs)
sc.doc.Views.Redraw()

Adds the point cloud to the document with the name attached…

1 Like