Hi,
you have function to retrieve the custom datatype corresponding to the custom gui you are adding. But not all gadgets works the same.
for CUSTOMGUI_PROGRESSBAR , you must send a message. DateTime you can either use the returned gadget or use FindCustomGui to update its data. CUSTOMGUI_QUICKTAB you can define the tabs in the CreateLayout function etc etc.
as FindCustomData says:
The method returns a BaseCustomGui when there is no class available for the custom GUI.
This allows to interact with any custom GUI, calling for instance BaseCustomGui.GetData()/SetData().
You can find this manual about the DateTime control/datatype.
Some gadgets could be restricted to Description and looks bad or not work in a GeDialog.
I wrote a plugin to test different cases and show how to use some gadgets.
import c4d
import collections
import os
from datetime import datetime
# Be sure to use a unique ID obtained from www.plugincafe.com
PLUGIN_ID = 9025250
class MemoryViewerDialog(c4d.gui.GeDialog):
def CreateLayout(self):
"""
This Method is called automatically when Cinema 4D Create the Layout (display) of the Dialog.
"""
self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 1)
self.dateTimeControl = self.AddCustomGui(1000, c4d.DATETIME_GUI, name="date time",
flags = c4d.BFH_SCALEFIT | c4d.BFV_FIT, minw=120, minh=30)
quickTabGadgetBC = c4d.BaseContainer()
quickTabGadgetBC.SetBool(c4d.QUICKTAB_SHOWSINGLE, True)
quickTabGadgetBC.SetBool(c4d.QUICKTAB_NOMULTISELECT, False)
self.quickTabGadget = self.AddCustomGui(1001, c4d.CUSTOMGUI_QUICKTAB, name="quick tab",
flags = c4d.BFH_SCALEFIT | c4d.BFV_FIT, minw=120, minh=30, customdata = quickTabGadgetBC)
self.quickTabGadget.AppendString(0, "First Tab", False)
self.quickTabGadget.AppendString(0, "Second Tab Selected", True)
self.AddButton(2000, c4d.BFH_SCALEFIT, 0, 0, "click me")
self.progressBarGadget = self.AddCustomGui(1002, c4d.CUSTOMGUI_PROGRESSBAR, name="",
flags = c4d.BFH_SCALEFIT | c4d.BFV_FIT, minw=120, minh=30)
self.GroupEnd()
return True
def Command(self, id, msg):
print (id)
if id == 2000:
timeDataType = self.FindCustomGui(1000, c4d.DATETIME_GUI)
print("this is timedata", timeDataType, self.dateTimeControl )
# Parse the time string
dt = datetime.strptime('16.07.2011 03:37:12',"%d.%m.%Y %H:%M:%S")
dtd = c4d.DateTimeData()
# Fills the Data object with the DateTime object
dtd.SetDateTime(dt)
timeDataType.SetDateTime(dtd, True, True)
progressMessage = c4d.BaseContainer(c4d.BFM_SETSTATUSBAR)
progressMessage.SetData(c4d.BFM_STATUSBAR_TXT , "this is displayed in the status bar")
self.SendMessage(1002, progressMessage)
return True
class MemoryViewerCommandData(c4d.plugins.CommandData):
dialog = None
def Execute(self, doc):
"""
Called when the user Execute the command (CallCommand or a clicks on the Command from the plugin menu)
:param doc: the current active document
:type doc: c4d.documents.BaseDocument
:return: True if the command success
"""
# Creates the dialog if its not already exists
if self.dialog is None:
self.dialog = MemoryViewerDialog()
# Opens the dialog
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID, defaulth=400, defaultw=400)
def RestoreLayout(self, sec_ref):
"""
Used to restore an asynchronous dialog that has been placed in the users layout.
:param sec_ref: The data that needs to be passed to the dlg (almost no use of it).
:type sec_ref: PyCObject
:return: True if the restore success
"""
# Creates the dialog if its not already exists
if self.dialog is None:
self.dialog = MemoryViewerDialog()
# Restores the layout
return self.dialog.Restore(pluginid=PLUGIN_ID, secret=sec_ref)
if __name__ == "__main__":
# Retrieves the icon path
directory, _ = os.path.split(__file__)
fn = os.path.join(directory, "res", "mviewer.tif")
# Creates a BaseBitmap
# Registers the Command plugin
c4d.plugins.RegisterCommandPlugin(id=PLUGIN_ID,
str="Py-MemoryViewer 2",
help="Show the current mem usage of Cinema 4D.",
info=0,
dat=MemoryViewerCommandData(),
icon=None)
Cheers,
Manuel