Move Tag Position in the Stack?
-
Hi,
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:
https://www.dropbox.com/s/k9apte4whn7cqvh/c4d211_move_tag_position.jpg?dl=0Thank you
-
Hi @bentraje,
I came across this problem some time ago.
Have a look at: https://www.lasselauch.com/c4d-quicktip-shift-tags/import c4d def main(): doc.StartUndo() 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): return #print """Tag: %s || Index: %s""" % (t.GetName(), i) doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj) obj.InsertTag(t, taglist[index]) doc.EndUndo() c4d.EventAdd() if __name__=='__main__': main()
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.
Cheers,
Lasse -
Thanks for the response. Gave me an idea what code to use.
Here is my working code:import c4d from c4d import gui # Select an object. # Hit Execute # Sets python tag in the right most place def main(): tag_list = op.GetTags() for tag in tag_list: if tag.GetType() == c4d.Tpython: op.InsertTag(tag, tag_list[-1]) c4d.EventAdd() main()
-
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.
Cheers, R
-
Gotcha. Thanks for the warning.