I`m noobie and working on simple script that should generate on selected layers Redshift Object tag with checked Object ID Override. Also I need to make uniqe Object ID numbers by adding 1 to each tag.
Problem: When I make loop through tags and try to increase Object ID parameters by 1 (I need 1, 2, 3,...) it pass all the tags exept the last and make the last tag Object ID parameter equal to objects quantity (9 in my case)
from c4d import gui
selection = doc.GetSelection()
collectedObjects = 
for s in selection:
c4d.gui.MessageDialog('Please choose objects')
for s in collectedObjects:
tag = c4d.BaseTag(1036222)
tag[c4d.REDSHIFT_OBJECT_OBJECTID_OVERRIDE] = True
for tags in range(len(collectedObjects)):
tag[c4d.REDSHIFT_OBJECT_OBJECTID_ID] += 1
Thank you for your attention!
it is easier just to answer in commented code, you will find anything there.
from c4d import gui
# This would also include tags and materials, i.e. is not what you
# selection = doc.GetSelection()
# This does not accomplish anything. 'selection' is already a list and
# you just build element by element a new list of it.
# collectedObjects = 
# if selection:
# for s in selection:
# c4d.gui.MessageDialog('Please choose objects')
# This part is technically okay, but we will consolidate it with the
# next loop.
# for s in collectedObjects:
# tag = c4d.BaseTag(1036222)
# tag[c4d.REDSHIFT_OBJECT_OBJECTID_OVERRIDE] = True
# doc.AddUndo(c4d.UNDOTYPE_NEW, tag)
# You never use your loop variable 'tags'. And you are referencing
# 'tag', which was the symbol for the BaseTag you did instantiate in
# the last loop. Because of that you will only increment the last tag
# you have created in this last loop over and over.
# for tags in range(len(collectedObjects)):
# tag[c4d.REDSHIFT_OBJECT_OBJECTID_ID] += 1
# If you want to enumerate some objects, you could just create a counter
# and increment it manually.
counter = 0
for char in ["A", "B", "C", "D"]:
print counter, char
counter += 1
# But that would not be very pythonic. Python has the wonderful function
# enumerate for this scenario, which will enumerate a collection object.
# This will only return the selected BaseObject nodes. See the docs for
# details. I did choose the flags so that we also include nodes that are
# not top level nodes and that the returned list reflects the selection
# order, which seems important in this case.
flags = (c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER |
selection = doc.GetActiveObjects(flags)
if not selection:
raise ValueError("No objects selected.")
for i, node in enumerate(selection):
# Since I do not own ReadShift, I will just be using the annotation
tag = c4d.BaseList2D(c4d.Tannotation)
tag[c4d.ANNOTATIONTAG_TEXT] = str(i)
@zipit I appreciate your answer. Thank you very much!
hi @SuperHomiak welcome to the forum.
Thanks @zipit for the answer
For your next threads, please help us keeping things organised and clean. I know it's not your priority but it really simplify our work here.
I've set the thread to a question and marked zipit answer as the right answer