texture tag script works but...

  • On 31/03/2013 at 07:25, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   r14 
    Platform:      Mac OSX  ; 
    Language(s) :   C.O.F.F.E.E  ;

    Here's a  script i did to change texture tags location.
    It's definitely not a slick one, but it works, except that...
    It makes the console giving error message each time i select an object when user_data#ID_USERDATA:2 == false.
    I tried different way to fixe it, really, never being able doing it.
    Is somebody could help me with it?
    Thanks a lot,

    Here's the links for the C4D scene(the second one in zip format).



    var user_data = doc->FindObject("temp_tag(f)");
    var tag_cntnr;//tag container
    var f_clnr;
    var f_txt_tg = new(array,2);
    var i;
    var i_tag;

    if (user_data#ID_USERDATA:2 == true)
    tag_cntnr = doc->FindObject("f1");
    if(!tag_cntnr) return;
    i_tag = tag_cntnr->GetFirstTag();
    if(!i_tag) return;
    i = 0;
    while(i< 2)
    f_txt_tg = i_tag;
    _ i_tag = i_tag->GetNext();_
    _ i++;_
    _ }_
    f_txt_tg[0]- >Remove();
    f_txt_tg[1]- >Remove();
    f_clnr = doc- >FindObject("f_1(clnr)");
    if(!f_clnr) return;
    f_clnr- >InsertTag(f_txt_tg[1]);
    f_clnr- >InsertTag(f_txt_tg[0]);
    if (user_data#ID_USERDATA:2 == false)
    tag_cntnr = doc- >FindObject("f_1(clnr)");
    if(!tag_cntnr) return;
    i_tag = tag_cntnr- >GetFirstTag();
    if(!i_tag) return;
    _ i = 0;_
    _ while(i< 2)_
    _ {_
    _ f_txt_tg = i_tag;_
    _ _ i_tag = i_tag->GetNext();__
    _ _ i++;__
    _ _ }__
    _ f_txt_tg[0]- >Remove();_
    _ f_txt_tg[1]- >Remove();_
    _ tag_cntnr = doc- >FindObject("f1");_
    _ if(!tag_cntnr) return;_
    _ tag_cntnr- >InsertTag(f_txt_tg[1]);_
    _ tag_cntnr- >InsertTag(f_txt_tg[0]);_
    _ }_
    _ }_

  • On 31/03/2013 at 08:01, xxxxxxxx wrote:

    Hello Jean.

    Please use the CODE BB-tags to format your code. Correct indentation makes reading the code far
    more easy, not just for you, but also for the ones that you are asking for help. Please provide
    and example scene: I am not willing to set up a scene that the script will operate on.

    Best regards,

  • On 31/03/2013 at 14:50, xxxxxxxx wrote:

    I added links for the scene.

  • On 01/04/2013 at 01:31, xxxxxxxx wrote:

    GeListNode.GetNext() returns null/nil if there are no other tags. please also note that there 
    are often more tags on objects than you can visually see. so simply iterating through all tags 
    is a very risky approach. the script is executed because c4d finds the modata tag on the cloner 
    object and therefore  _i_tag = tag_cntnr- >GetFirstTag(); _is not null _ _ but getnext() will return then 

    edit : also doing such object tree manipulation from a expression is pretty dangerous. also
    this whole copy, delete, insert approach is a bit clunky and object names as identifiers are a 
    bad idea. however here is a quick version (in python) how to move all texture tags from one 
    object to another.

        obja = doc.SearchObject('f1')
        objb = doc.SearchObject('f_1(clnr)')
        if obja and objb:
            for tag in obja.GetTags() :
                if tag.CheckType(c4d.Ttexture) :

  • On 01/04/2013 at 08:07, xxxxxxxx wrote:

    Thanks a lot ferdinand.
    I don't know Python, but i'm whiling to give it a try.
    I copied and paste your Python's script into a Python's tag.
    It doesn't execute probably needing some declaration...
    Could just give me a clue so i could at least execute those lines of code you gave me?
    Thanks again.

  • On 01/04/2013 at 09:41, xxxxxxxx wrote:

    just paste the snippet into main method of a script or expression, something like this:

    import c4d
    #Welcome to the world of Python
    def main() :
        obja = doc.SearchObject('f1')
        objb = doc.SearchObject('f_1(clnr)')
        if obja and objb:
            for tag in reversed(obja.GetTags()) :
                if tag.CheckType(c4d.Ttexture) :

  • On 01/04/2013 at 11:15, xxxxxxxx wrote:

    Thanks ferdinant,
    It works.
    Then i just tried to add my "switch" status, so i could move tags from one object to the other and get it back.
    But it's  not responding  to it...
    Cannot figure how to nest [if] into [if]...
    In fact, i have 6 switchs, each one for a set of tags, but tried to make it works with one switch first.
    Sorry, it's a first try with Python, but i really appreciate your help.

    import c4d

    def main() :
        obja = doc.SearchObject('f1')
        objb = doc.SearchObject('f_1(clnr)')
        if [c4d.ID_USERDATA,2] == 0:
            if obja and objb:
             for tag in reversed(obja.GetTags()) :
                if tag.CheckType(c4d.Ttexture) :
                    if [c4d.ID_USERDATA,2] == 1:
                        if obja and objb:
                         for tag in reversed(objb.GetTags()) :
                            if tag.CheckType(c4d.Ttexture) :

    Then i should continue with  [c4d.ID_USERDATA,3]  with object name ('f2') ('f_2(clnr)'), etc...
    Hope that at least i'm clear with what i'trying to do.

  • On 01/04/2013 at 22:46, xxxxxxxx wrote:


    the bracket syntax ([SOMEID]) is a shortcut to the __getitem__ and __setitem__ methods 
    which basically just access the basecontainer of an object. so you need an object for which 
    you could invoke those methods.

    > if myobj[c4d.isawesome]: ...

    you will need the object holding your user data for that. i think it is worth mentioning in that
    context that there are some predefined variables for each python script and expression, one
    of them is op which is pointing / is a reference to the hosting object, which would be for your
    case a pyhton tag.

    so if you had your userdata attached to a null object which is also hosting your python tag
    your code would be something like this. (GetObject() is a BaseTag method returning the 
    hosting BaseObject for a BaseTag).

    myUDHost = op.GetObject()
    if myUDHost[c4d.isawesome]:

    for your general code syntax, you are aware that 50% of your code will never be executed ?
    nesting if a == False withing an a == True does not make sense a cannot be both true and false.
    you are most likely just looking for something like this:

    if conditionA:         // will always be true, unless conditionA is 0, False or None
    elif not conditionA: // inverted - only true if conditionA is 0, False or None
    elif conditionA == 3:  // the following lines would never be executed because the previous conditions already covered all cases, so just for the record
    elif conditionA == 'someText':
    elif objA == objB:
    elif objA is objB:

  • On 02/04/2013 at 07:58, xxxxxxxx wrote:

    Hi ferdinand,
    V'got some home works...
    I tried to paste this snippet you gave me into Python Script Manager to execute it with a short cut and it didn't work.
    Is it possible to execute it from there that way?
    May be you already told me in your previous reply, but i'm looking for a quick workaround way to use this snippet.
    Thanks again,
    import c4d
    #Welcome to the world of Python

    def main() :
        obja = doc.SearchObject('f1')
        objb = doc.SearchObject('f_1(clnr)')
        if obja and objb:
            for tag in reversed(obja.GetTags()) :
                if tag.CheckType(c4d.Ttexture) :


  • On 02/04/2013 at 09:02, xxxxxxxx wrote:

    for a script you have to add:

    if __name__=='__main__':

    at the bottom of your script.

  • On 02/04/2013 at 11:08, xxxxxxxx wrote:

    Hi ferdinand,
    Thanks a lot!

Log in to reply