accessing tag types with python



  • On 09/03/2017 at 05:42, xxxxxxxx wrote:

    Hi everyone,

    I'm having trouble getting my head around the syntax for working with tag types.

    i iterating through my object hierarchy and on the current object calling a fucntion to list the tags on that object.

    I successfully have that at list. I would then like to check if a certain tag is in that list, i.e.

    if thisTag in tags:
    # do this
    elif otherTag in tags:
    # do this

    I understand how to get the type name: Tagtype = tag.GetTypeName()

    and i know how to check if a tag is a certain type.. but if I know the type and i want to check if that type is a list of stored tags.. how do i do it?

    (I find the syntax for this and the documentation rather confusing)

    I might just be running in circles here and missing the point but please any advice would be much appreciated! ;)

    Many thanks
    David



  • On 09/03/2017 at 23:09, xxxxxxxx wrote:

    well this seems to be what I was looking for... 
    yet got to implement it with the rest of the code but it seems to be working as I wanted.

    the syntax for this was incredibly hard to find for me, having scoured the internet for hours. I guess more probable is that I didn't know how to best look for it, but still found the help info on this a bit sparse.

    I found a hint here:
    https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/C4DAtom/GeListNode/BaseList2D/BaseTag/VariableTag/

    But would have sort of expected to find some hints or links how to use these types on this page:
    https://developers.maxon.net/docs/Cinema4DPythonSDK/html/types/tags.html

      
            if obj.GetTag(c4d.Ttexture) and not obj.GetTag(c4d.Tuvw) in tags:
                print "We only got a Texture tag here"
            elif obj.GetTag(c4d.Ttexture) and obj.GetTag(c4d.Tuvw) in tags:
                print "we got both a Texture tag and a UVW tag here"
            elif obj.GetTag(c4d.Tuvw) and not obj.GetTag(c4d.Ttexture)in tags:
                print "We have only a UVW tag here"
      
    
    


  • On 10/03/2017 at 05:23, xxxxxxxx wrote:

    Hi,

    welcome to the Plugin Café forums 🙂

    I'm sorry you had problems finding a solution in the documentation, but also glad you did in the end.
    We are aware our SDK documentations are not the best in all cases (for the lack of better words...), but at least we are working on it. But we can only get done so much at a time and currently we are concentrating on the C++ docs. These are being extended by, what we call, "overviews" and "manuals". These currently contain only C++ code snippets, but may already be useful for Python developers as well.

    In your case it's probably the C4DAtom and the BaseList2D manuals (a BaseTag is derived of these classes). That's probably also the reason you didn't find the information you were looking for in the BaseTag/VariableTag API reference.

    To your initial question, there's not only one solution.

    Yours could be a bit optimized, by assigning the return values of the two GetTag() calls to local variables and use these instead in your "if" statements. Then I should add, that an object could have multiple tags of each type and with GetTag() you are getting only the first of each type (which might be, what you want).

    Another option would be to use GetFirstTag() and then loop through all tags using GetNext(), storing a flag for each encountered tag type of interest.

    In the end I'm not completely sure, if your actual question might have been, where do I find the IDs of tags?
    There we currently do not have a very good solution (i.E. one table containing them all, but all the means discussed in this forum multiple times to obtain IDs work for tags as well: resource files in C4D install folder under resource/modules or dragging tags to the input filed of the Console window.
    Or you can visit the homepage of GameLogicDesign, they provide a pretty nice overview there: IDs sorted by type



  • On 10/03/2017 at 10:47, xxxxxxxx wrote:

    Andreas,
    Thank you for your extensive answer! 
    I've been aware of the C++ docs and how they cover some of the aspects available to python too. It's still hard tho to get that cross ref while searching online. Im looking forward to the python docs being more complete for cinema 4d.

    Thanks for your suggestions! Yes I've refactored now and I found some information regarding GetFirstTag() and GetNext() too. I certainly will need those so thats a great hint.

    My initial question was really a general request for simple examples on how to work with tags, how to best find them and modify them.. its a bit uncertain knowing that they can by called by either name, type or ID and not knowing which is more efficient or which one would work in a certain situation. A lot of trial and error and chance and in the long run it would be cool to know that there is a more steadfast way to arrive at the desired result.

    In the end though the excitement of getting it to work usually wins over the discomfort of ultimately arriving there ;)

    I'll be back with more questions im sure
    thanks .david



  • On 13/03/2017 at 09:17, xxxxxxxx wrote:

    ok Im back with a working solution, but I'm stumped with a specific List issue, which does seem to work but which I do not understand..

    I'm posting the function here, in hope that its self explanatory in itself. The args like objName etc are defined earlier in the chain of callback functions

    What I don't understand is why my list "checkTags = []" wich is currently placed inside the "while loop" only prints out one value even if an object contains several texture tags?

    I am getting the correct result out of the full script and this function is the main engine, so all in all it does work, i just don't understand why.

    I would have expected the checkTags list to print out all the texture tags on an object and then after that only pic to work with the ones where the objName matches in the follwoing for loop using the checkTags list.

    Sorry this feels a bit like Im rambling but its hard to explain. Hopefully someone can see some clarity

    any advice much appreciated!

    Thanks David

    def checkTags(obj, objName, matList, matNames) :
        objTEX = obj.GetTag(c4d.Ttexture)
        objUVW = obj.GetTag(c4d.Tuvw)
        tag = obj.GetFirstTag()
        tags = obj.GetTags()
        proj = None
      
        # check if there is a TEX tag on the object but no UVW tag
        if objTEX and not objUVW in tags:
            while tag: 
                checkTag = []
                if tag == objTEX:
                    checkTag.append(tag)
                if not tag.GetNext() :
                    break
                tag = tag.GetNext()
            print checkTag
            # check the new temp list for name of tex tags
            for tTag in checkTag:
                if tTag.GetMaterial().GetName() == objName:
                    return False
                else:
                    proj = 'cubic'
                    placeTag(obj, objName, matList, matNames, proj) # call tag placement funcitons with CUBIC
        
        elif objTEX and objUVW in tags:
            while tag:
                checkTag = []
                if tag == objTEX:
                    checkTag.append(tag)
                if not tag.GetNext() :
                    break
                tag = tag.GetNext()
            # check the new temp list for name of tex tags
            for tTag in checkTag:
                if tTag.GetMaterial().GetName() == objName:
                    return False # do nothing
                else:
                    proj = 'uvw'
                    placeTag(obj, objName, matList, matNames, proj) # call function to place tag - UVW
    

Log in to reply