SOLVED Get CustomGUI Data in python

Hello plugincafe!
I have recently created a customgui using the example customgui plugin. The only major thing that I changed, appart from drawing, is that I save a single float value.
I now need to implement this custom gui into a python plugin but I can't seem to find out how to retrieve my saved data from the gui element.

Do I need to completely switch to a c++ plugin to do this, or is there a way in python.

Kind Regards,
Florian

Hi if your data type is already a know python type you shouldn't have any issue and could use the BaseCustomGui.GetData / BaseCustomGui.SetData.

So if we take the C++ example of the String Custom GUI.
You can use it in Python like bellow:

import c4d

ID_CUSTOM_GUI = 1001
ID_BUTTON_DO = 1002

class myCustomGuiDlg(c4d.gui.GeDialog):
    
    def CreateLayout(self):
        
        self._customGui = self.AddCustomGui(ID_CUSTOM_GUI, 1034655, 'my value', c4d.BFH_SCALEFIT, 50, 10)
        self.AddButton(ID_BUTTON_DO,c4d.BFH_SCALEFIT,name = 'Get Data')
        return True
    
    def InitValues(self):
        self._customGui.SetData("Some custom text")
        return True
    
    
    def Command(self, id, msg):
        if id == ID_BUTTON_DO:
            print self._customGui.GetData()
            
        return True
    

if __name__=='__main__':
    dlg = myCustomGuiDlg()
    dlg.Open(c4d.DLG_TYPE_ASYNC)

Cheers,
Maxime.

Hello Maxime,
thanks for you answer!
I actually have my custom gui not in a GeDialog but inside a res file of an ObjectData. How would I be able to access the customgui from there?

Best Regards,
Florian

In an ObjectData plugin, you don't access GUIs. You access parameters. So what is the parameter type that is using your custom GUI? Can you show your *.res file?

Hello Sebastian,
basically I have something like this

[...]
MY_CUSTOMGUI CUSTOMGUIPARAM { }
[...]

that is what I use.

Sorry, but this is not how it works. A NodeData's res file looks like this:

STRING ID_RESULT_TEXT  { CUSTOMGUI MULTISTRING; ANIM OFF; }

The first symbol is the data type (STRING), the second the parameter ID, The custom GUI can be found after the CUSTOMGUI keyword.

So in your case, MY_CUSTOMGUI is NOT a custom GUI. It is a custom data type. Is that correct?

oh... yeah that is true.

I edited the customdata_customgui example to fit my needs. (mainly only the drawing).
So I guess I would have to change my customdata to a REAL customgui?

Please make sure you understand the difference between a data type and a GUI. A data type stores data of some type. A GUI displays that data and allows interaction with that data in the UI. But it does not persistently store the data.

So if you want to have a parameter in your object that stores a float value, just use a REAL parameter. You can display that parameter in the UI using a custom GUI element. See for example customgui_string.cpp.

best wishes,
Sebastian

Hello Sebastian,
I now understand what the difference is, thank you very much!
With the customdata_customgui example file I actually made both a GUI and a custom DataType. So I only needed to change my resource file and modifiy my data code a bit!

Best Regards,
Florian