Error "name required when object_id represents multiple objects"

Hi

I am total newbie
I am trying to make a script that copy several objects and then add a surfix to the name.

Right now I just made a small script to print the objects name.
But when I do run it it get this error:
name required when object_id represents multiple objects

Can anybody help make the script work

Here is the script for print names:

import rhinoscriptsyntax as rs

obj =rs.GetObjects()
names = rs.ObjectName(obj)
print names

Hope someone will help me :slight_smile:

GetObjects() allows one to pick multiple objects and thus returns a list (even if it’s a list of just one item).

ObjectName() accepts only one object, not a list. So you will need to loop through the list returned by GetObjects() and feed the list members to ObjectName() one at a time.

Example:

import rhinoscriptsyntax as rs

objs=rs.GetObjects()
#this is your loop
for obj in objs:
    obj_name=rs.ObjectName(obj)
    print obj_name
    #you could do something else with the object name, i.e. add a suffix, etc.

There is no error checking in the above, it does not check if any objects have actually been selected by GetObjects() or if the selected objects have a name. That would need to be added.

Thanks !

I have succesful got a list with names. However when I add a surfix to the objects name, it only add the surfix to the last name in the list.
Got any advise for how to overcome this ?

naming_help.py (457 Bytes)

That’s kind of a confusing script. I might do it this way:

import rhinoscriptsyntax as rs

objs =rs.GetObjects()
if objs:
    #are you really wanting to create copies of the objects?
    copies = rs.CopyObjects(objs)
    mb1 = rs.MessageBox("Add suffix?", 4)
    if mb1 ==6:
        #can also ask the user for suffix via rs.StringBox()
        suffix="-suffix"
        #create a counter for objects that have names
        named_obj_count=0
        #now run your loop
        for obj in copies:
            obj_name=rs.ObjectName(obj)
            if obj_name:
                #means the object had a name, add suffix
                new_name=rs.ObjectName(obj,obj_name+suffix)
                #increment the counter
                named_obj_count+=1
        #reporting
        if named_obj_count==0:
            #no objects had names
            msg="No named objects found"
        else:
            msg="Added suffixes to {} objects".format(named_obj_count)
            #the format statement inserts the counter value inside the brackets
        print msg

Feel free to ask questions on the procedure if there is something you don’t understand.

thanks