SOLVED How to add Button User Data with a Button GUI in python script?

Hi,

How can I add a button to an object with python?

I'm trying to add a button to a Null Object, but only get a button userdata without button itself. Here is the code:

import c4d

def main():
    null_object = c4d.BaseObject(c4d.Onull)

    ud_btn_bc = c4d.GetCustomDatatypeDefault(c4d.DTYPE_BUTTON)
    ud_btn_bc.SetString(c4d.DESC_NAME, "Click")
    ud_btn_bc.SetString(c4d.DESC_SHORT_NAME, "click")
    null_object.AddUserData(ud_btn_bc)

    doc.InsertObject(null_object)
 
    c4d.EventAdd()

if __name__ == "__main__":
    main()

It seems that creating a button user data from GUI is different from Python. But I don't know how to do it correctly in Python.

Thanks!

hi,

the function 'GetCustomDatatypeDefault' do not always return a BaseContainer with DESC_CUSTOMGUI defined. In the case of the 'Button' datatype, the returned BaseContainer is empty. You must define the custom GUI you want to use.

In your case using ' ud_btn_bc.SetInt32(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_BUTTON)' will work.

Cheers,
Manuel

hi,

the function 'GetCustomDatatypeDefault' do not always return a BaseContainer with DESC_CUSTOMGUI defined. In the case of the 'Button' datatype, the returned BaseContainer is empty. You must define the custom GUI you want to use.

In your case using ' ud_btn_bc.SetInt32(c4d.DESC_CUSTOMGUI, c4d.CUSTOMGUI_BUTTON)' will work.

Cheers,
Manuel

It works like a charm!

Thanks a lot!