How do I move the tag position in stack? For instance, moving the python tag into the farther right.
You can check an illustration of the problem here:
I came across this problem some time ago.
Have a look at: https://www.lasselauch.com/c4d-quicktip-shift-tags/
sel = doc.GetActiveTags()
for tag in sel:
obj = tag.GetMain()
taglist = obj.GetTags()
for i, t in enumerate(taglist):
if t in sel:
index = i+1
if index == len(taglist):
#print """Tag: %s || Index: %s""" % (t.GetName(), i)
This was essentially my approach, it’s not bulletproof but it works if you want to send multiple tags from one index to the next.
Thanks for the response. Gave me an idea what code to use.
Here is my working code:
from c4d import gui
# Select an object.
# Hit Execute
# Sets python tag in the right most place
tag_list = op.GetTags()
for tag in tag_list:
if tag.GetType() == c4d.Tpython:
Hi @bentraje, thanks for reaching out us.
With regard to the solutions offered by @lasselauch - kudos Lasse - I have to remind that you're both benefiting of a automatism found in the Python implementation of the BaseObject::InsertTag(): when the method is called in Python, before inserting the tag, it first gets removed from the previous owner and then is inserted in the new one.
This is very convenient and delivered for free in the Python implementation, in C++ this is not and this should be took in consideration.
Finally, one note about the code design: it could lead to unpredictable results, especially on more complex scenarios, re-ordering a list while iterating on the same list. I would rather suggest iterating on list and operate the reorder on a copy of such list.
Gotcha. Thanks for the warning.