Rename objects with Python scripting in Grasshopper

Hi there,
I am trying to change the name of a list of points with Grasshopper Python scripting. I have as inputs:

  • one list containing the set of points
  • another list containing the name that I want to assign to each point.
    I found out the command rs.ObjectName can be used to this purpose, but there is something that I am missing in the Python code.
    Can anyone of you help me out in solving this issue? I attach an image to show the problem
    Thank you in advance to anyone who will answer

I believe you need to change the scriptcontext

Like so…

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
 
#go rhino
sc.doc = Rhino.RhinoDoc.ActiveDoc
rs.AddCurve(x)
 
#back to gh
sc.doc = ghdoc

or you can use human or elefront to change the name via component.

Dear Rickson,
thank you for your reply. However, I still cannot figure out how to solve my problem… I attach the file for more explanation.
The points that I have are created on Grasshopper and are not picked up from Rhino, for this reason I think the command “Modify Rhino Object attribute” doesn’t work.
Could you please help me out? isn’t there an easier way to do it by Python scripting?

20201111_Superficie rettangolare e cilindrica.3dm (41.6 KB) 20201111_Superficie rettangolare e cilindrica.gh (15.9 KB)

    1. List item

The points are added to Rhino via rs.AddPoint, so you will need to change the scriptcontext to rhino to add the point and subsequent name.

You can use human or elefront to bake your grasshopper points in rhino with attributes such as name, layer or user defined.

Ok thank you, but do you have any suggestions on what was the problem with my original script?

needs scriptcontext, i also set the point input to cast Point3D as a list.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
 
#go rhino
sc.doc = Rhino.RhinoDoc.ActiveDoc
for pt in points:
    for n in names:
        rpt = rs.AddPoint(pt)
        a = rs.ObjectName(rpt, n)
#back to gh
sc.doc = ghdoc

Thank you again for your help.
However, typing this code within my file still gives me an error. Could you please try it directly on my file? I really cannot understand the reason why I am still stuck on this problem even though it should be relatively simple to add an attribute value to a list of elements by communication between Rhino and Grasshopper. I even tried with Elefront and Human UI but it looks like their commands do not work with lists?

what error?

the Elefront and Human work great, you will have to be more specific.

Has anyone found a solution to renaming the Name to the Rhino Elements?

Using Human Plugin. Works