Setobjectname - append logic?

Hello,

Can anybody shed some light on how the “setobjectname” command with the append option turned on works? For example, I have multiple objects selected and I want to give them a name, but with an incremented number afterwards (just like the command does). However, I can’t seem to determine the logic in terms of the order of the numbering that Rhino applies… they get uniquely numbered but not in a pattern that I can see.

What I ideally want to do is assign a name and number them sequentially based on position in 3D space (i.e. along the z-axis). I have thousands of objects to name and don’t really want to have to name them all them manually! :slight_smile:

Thanks!

1 Like

From what I can see if you run the command and then manually select items one by one, then the command will number the items in the order that you select them, but if you window drag and group select a whole lot of items to name then the numbering seems to be in sequence but the numbering direction is not predictable.

Additional Request: Possibly also an option to set the starting number; be it 0, 1 or perhaps a higher number in case you want to continue numbering additional items from a previous naming session
eg. There are already 20 x items but now you need to name an addition 10 from 21-30 etc. without starting from 0 again.

This is very simple to do with a script. I don’t have time tonight unfortunately… Based on what Z coordinate though? Top, middle or bottom of bounding box? Something else?

–Mitch

In my case, the objects are triangle mesh objects (each mesh only has one triangle). I would base the naming on the centroid of the triangle (the average Z of the 3 vertices)… I’m not asking anybody to write a script for me, but it that is how the best solution to the problem is going to happen, some pointers to start me in the right direction wouldn’t go amiss. Thanks.

OK, here is a draft of a solution… Let me know how it works for you… --Mitch

"""Names and numbers mesh objects by mesh centroid Z coordinate
    Option to sort in ascending or descending order
    Name is user assigned prefix plus number based on Z coordinate order
    Script by Mitch Heynick 18.09.14"""

import rhinoscriptsyntax as rs

def NameNumberMeshObjsByZ():
    objs=rs.GetObjects("Select meshes to name and number",32,True)
    if not objs: return
    
    prefix=rs.GetString("Name prefix?")
    if not prefix: return
    
    gb=rs.GetBoolean("Order",["SortBy","Ascending","Decending"],[True])
    if not gb: return
    
    centroids=[rs.MeshAreaCentroid(obj) for obj in objs]
    cZ=[pt.Z for pt in centroids]
    cZF=zip(cZ,objs)
    cZF.sort(reverse=gb[0])
    for i in range(len(cZF)):
        rs.ObjectName(cZF[i][1],prefix+"-{}".format(i+1))       
    
NameNumberMeshObjsByZ()

That works perfectly! I’d call that a final copy, not a draft!

Thanks for going the extra mile - you didn’t have to but I’ll take it!

OK, glad the script works. This can be generalized to other objects besides meshes and there are lots of other possibilities for object naming.

To answer your original question, if you set AppendCounter=Yes, the order is either:

  1. the order in which you picked the objects if you selected them individually,

    or

  2. the inverse of the order in which the objects have been added to the file if you did not pick them individually - i.e. window select, etc. Thus the most recent object will have the lowest number (numbering starts with 0) and the oldest object will have the highest number…

1 Like