How do you cycle and select(in the editor) tags

On 27/07/2016 at 05:45, xxxxxxxx wrote:

Suppose I have an object with multiple tags I want to select by condition (in the editor) how do I select them ?

I'm writing a simple snippet to do so :

  
def main() :
    
    doc = documents.GetActiveDocument()
    obj = doc.GetActiveObject();  # Get Active Object
    
    print obj
    
    for t in obj.GetTags() :
  
        if (t.GetType() == 5673) : # 5673 = SelectionTag
            if "ABCD" in t[c4d.ID_BASELIST_NAME] :  
  
                pass 			# Add code to select the tag in the editor
                
if __name__=='__main__':
    main()

I left a pass where I don't know how to proceed.

On 27/07/2016 at 08:25, xxxxxxxx wrote:

Heya!

SetActiveTag() is what you're looking for :)

If you want to deselect all other tags first, you can doc.SetActiveTag(None), and then doc.SetActiveTag(tag, c4d.SELECTION_ADD) after that.

So in the end it might look like:

def main() :
    
    doc = documents.GetActiveDocument()
    obj = doc.GetActiveObject();  # Get Active Object
    
    print obj
    doc.SetActiveTag(None)
#doc.SetActiveObject(None), if you like
    for t in obj.GetTags() :
  
        if (t.GetType() == 5673) : # 5673 = SelectionTag
            if "ABCD" in t[c4d.ID_BASELIST_NAME] :  
  
                doc.SetActiveTag(t, c4d.SELECTION_ADD)
                
if __name__=='__main__':
    main()

On 27/07/2016 at 09:17, xxxxxxxx wrote:

Thanks this is really useful.
Exactly what I was trying to do. :slightly_smiling_face: