How to modify the name field for all that "Set Selection" was applied to?


#1

Hello,

I’m a super newb and I’m being asked to write a script that:

  1. selects a material
  2. Selects the materials tags/objects
  3. Switches to face mode
  4. Selects all (while in face mode)
  5. applies “Set Selection” to all of the selected
  6. Renames all of the new Set Selection tags with the same name

I more or less think I have figured out all of the first five steps by using CallCommand, but I am not sure how to get the newly created Set Selection tags pythonically and rename them. Any help would be appreciated,


#2

I figured out a solution so I’m putting the answer here for anyone in the future who may need to do this:

to rename the set selection tags, first store everything selected:
selected = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
then store all of the Polygon Selection tags that each object has in a dictionary:
object_tags = {} for object_selected in selected: tags = [] for tag in object_selected.GetTags(): if tag.GetType() == 5673: # Polygon Selection tags.append(tag) object_tags[object_selected.GetName()] = tags
then call Set Selection:
c4d.CallCommand(12552)
then repeat the above code loop to find all Polygon Selection tags, and compare against the originals:
object_tags = {} for object_selected in selected: old_tags = object_selected.GetName() new_tags = [] for tag in object_selected.GetTags(): if tag.GetType() == 5673: # Polygon Selection new_tags.append(tag) latest_tag = [x for x in new_tags if x not in old_tags] if latest_tag: latest_tag[0].SetName(whatever_you're_naming_your_set)

Hopefully this helps someone!