Special Options - creating UserData with Python



  • On 19/06/2013 at 11:01, xxxxxxxx wrote:

    You can change any UD option. But to do that you first have to understand how UD works.
    You have to understand how the sub containers work in the UserData master container object.
    Once you understand how to get at the sub containers. And understand what's inside of them. You can change pretty much any UD option there is.

    I've already explained how to do this in this thread:https://plugincafe.maxon.net/topic/7119/8084_add-userdata-with-details

    Here is an example of how to set the string option to STRINGMULTI mode on your first UserData item.

    import c4d  
    def main() :  
        
      obj = doc.GetActiveObject()      #The object hosting the UD    
      ud = obj.GetUserDataContainer() #The master UD container  
         
      first = ud[0]                   #The first UD entry on the stack (not it's ID#)  
      bc0 = first[0]                  #The first tuple container of options(DescID stuff)   
      bc1 = first[1]                  #The second tuple container of options(UD options)  
       
      for i in bc1: print i           #Shows you all the options you can change by their ID#           
      
      #You have two ways to change the UD's options  
      #By using it's ID# found in the lib_description.h file like this:  
      #first[1][21] = 200000007       #Sets the STRINGMULTI option  
        
      #Or by using the text based name for the ID#(preferred by Maxon) :  
      bc1.SetLong(c4d.DESC_CUSTOMGUI,c4d.CUSTOMGUI_STRINGMULTI)    #Sets the STRINGMULTI option  
      
      obj.SetUserDataContainer(bc0, bc1) #Set the container changes  
        
      c4d.EventAdd()  
      
    if __name__=='__main__':  
      main()
    

    The first time you look through those UD sub containers it will probably feel rather confusing.
    I've tried to spell out what they do as much as I could. But each type of UD gizmo has it's own set of container data. So you'll have to take some time and experiment with them to try and get comfortable with finding, and changing them.

    -ScottA



  • On 19/06/2013 at 12:03, xxxxxxxx wrote:

    @ scott using plain ids is not a good advice imho. also your code example is very
    cppish imho, no offense.

    @ op your fault seemed to be that you did not pass the id properly.

    import c4d
        from c4d import gui
        #Welcome to the world of Python
        
        def main() :
            if op:
                nextID = len(op.GetUserDataContainer()) - 1
                bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_STRING)
                bc[c4d.DESC_NAME] = 'Static string'
                bc[c4d.DESC_CUSTOMGUI] = c4d.CUSTOMGUI_STATICTEXT
                op.SetUserDataContainer([c4d.ID_USERDATA, nextID], bc)
                c4d.EventAdd()
                
        if __name__=='__main__':
            main()
    


  • On 19/06/2013 at 13:22, xxxxxxxx wrote:

    hello,

    absolute great! thanks a lot! the problem with the special type is working great :)

    The only thing remaining is the problem with the default open group :(
    Do you maybe have an other idea how to solve it?

    bc[c4d.DESC_GUIOPEN] = True
    

    does not work :(

    greetings,
    Christopher



  • On 19/06/2013 at 14:15, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    @ scott using plain ids is not a good advice imho. also your code example is very
    cppish imho, no offense.

    Actually. I do take offense to that comment. Because I also showed how to write it with text based descriptions. And I even went as far putting a comment that it's the Maxon recommended way.
    So I can't think of any reason why you would even bring that up.  Other than personal reasons.

    And as for your cppish remark.
    IMO. It's very important to understand how UD works. And that requires seeing the containers in their raw form without any python covering them up.
    Once you know how the containers work. Then the users can write code in a more pythonic manner if they wish. But they need to know how it works first.

    -ScottA



  • On 19/06/2013 at 14:48, xxxxxxxx wrote:

    yea, you are absolutly right! the main issue is, to understand the tools and objects, that are used!
    It is much better then just to get the solution without understanding, what is happening there.

    But still, in my case the command (two posts aboph) is not working :(

    greetings,
    Chriss



  • On 19/06/2013 at 16:36, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    yea, you are absolutly right! the main issue is, to understand the tools and objects, that are used!
    It is much better then just to get the solution without understanding, what is happening there.

    But still, in my case the command (two posts aboph) is not working :(

    greetings,
    Chriss

    yeah, now that you wrote it ... the OPEN flag in descriptions is used to toggle the state of 
    things like color fields or spline guis. Groups are set with DEFAULT 0|1. So my guess was kind
    of pretty wrong ;) You might want to try your luck with the ID for the default value.



  • On 19/06/2013 at 19:30, xxxxxxxx wrote:

    If you are referring to the "Default Open" option for UD groups.

    The ID for that one isn't: c4d.DESC_GUIOPEN
    It's: c4d.DESC_DEFAULT

    -ScottA



  • On 24/06/2013 at 15:31, xxxxxxxx wrote:

    you are all my absolute heroes. Thanks a lot!
    Everything is now working just fine ... most of the tings :P
    Only one last little question:

    the command

    bc[c4d.DESC_COLUMNS] = 3
    

    does not change the amount of colums in a group.
    Because of that, I searched a littlebit in this board and came up with this solution:

    bc[22] = 3
    

    it is now working! My group now has tree columns.
    But I wondered, what command is behind the "22"?
    is there a other way to write the "bc[22]"? maybe something like "bc[DESC_xxxxxx]"?

    greetings,
    Chriss



  • On 24/06/2013 at 15:59, xxxxxxxx wrote:

    I don't  know if this was a typo on your part. But you forgot the c4d. prefix in your DESC_COLUMNS example.
    But it's possible that it doesn't work even with the c4d prefix(I haven't tested it myself to see).
    There are still some things that have not been linked to a text based symbol ID# yet.  And you'll have no choice but to use the numeric ID#.

    Most of the UD ID#s can be found in the file: C:\Program Files\MAXON\CINEMA 4D R13\resource\_api\c4d_libs\lib_description.h

    In that file. There is an entry:  DESC_COLUMNS = 22
    If Sebastien hasn't linked the text based name to that ID number. Then you'll have to use the actual number until he sets it up to use the text based ID's.

    -ScottA



  • On 24/06/2013 at 16:48, xxxxxxxx wrote:

    hey,

    thanks a lot for the fast reply!
    And yes, you are right, I forgot the "c4d." in front of the tag^^
    This can happen if you write the code without copy&past :P

    The interesting fact here is, that the id 22 seems to be linked to "DESC_COLUMNS" but will not work. maybe it is more a bug, then a missing connection. But whatever the case is, it only works with the id.
    But thanks also for the c++ header file. this one was new to me, so now I know where you guys get all the text based sybols :P

    But in this case I have an other little question:

    I found this userdata in an project and thought this is very interesting, because there is no actual data type and this is only a kind of "dummy" in order to seperate two userdatas.
    So two of this userdatas can make a "space"/"gap" in a group in order to sort the things a little better.
    _<_img src="http://weltderpixel.com/dd/c4d board.jpg" border="0" /_>_

    But how can I create such an userdata with python?
    And how can I create it without python?

    I have really no idea how to create this userdata. Not with the normal c4d method and also not with python. Maybe someone can help me with this one.
    It would be really nice!

    greetings,
    Chriss

    [EDIT] ah, sry, I now see that the image is not 100% in english. But I think, that you all know, what the names stand for :P ... and if not, then tell me and I will change it!



  • On 24/06/2013 at 17:05, xxxxxxxx wrote:

    The only time I've seen something like that is when I accidentally created a UD entry with an ID# of zero.
    UserData entries are supposed to start at 1. And C4D doesn't like it when a zero ID is used.
    But since the ID# is 30 in your example. I can't really say what's going on in that one.

    UserData is basically a tree with invisible branches. And the actual UD gizmos themselves are like leaves on the branches.
    Using things like PopId() & PushId() you can build a UserData tree with empty branches in it that don't have a UD gizmo on it/them. And this can possibly be used to do some special tricks like what you're got there.

    -ScottA


Log in to reply