CommandData ExecuteOptionID()
-
Hello,
Could someone please help me with a working example of CommandData.ExecuteOptionID()? I was unable to find one online and I find the documentation confusing. I would like to transfer the data from a GeDialog storing Options to my CommandData plugin. What would this look like?Documentation Confusion
ExectuteOptionID() accepts subid as an argument, which is described as such:subid (int) β Only available for plugins that have sub-IDs (which normally are called using ExecuteSubID().
Is this saying that I should call ExecuteSubID() as well or does ExecuteOptionID() replace this method?
In ExecuteSubID(), it then says:
Override - Execute the command plugin with the subid that was given by GetSubContainer().
Is this saying that I need to also call GetSubContainer()? How does this work?
What I Have So Far
Options Dialog...
class Options_Dlg(c4d.gui.GeDialog): # options data, CreateLayout, etc.
From CommandData...
def ExecuteOptionID(self, doc, plugid, subid): dlg = Options_Dlg() dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=150) return True
Registering the Command Plugin...
c4d.plugins.RegisterCommandPlugin(id=CMD_PLUGIN_ID, str="Plugin Name", info=c4d.PLUGINFLAG_COMMAND_OPTION_DIALOG | c4d.PLUGINFLAG_COMMAND_HOTKEY |c4d.PLUGINFLAG_HIDEPLUGINMENU, help="Help text.", dat=MyCommandData(), icon=None)
Thank you.
-
Hi,
it is a bit unclear to me what your actual question is.
CommandData.ExecuteSubID
is called when you did overrideCommandData.GetSubConatiner
. This will define sub IDs and menu entries to split your command into. Probably not what you are currently after.If you want to transfer data from your dialog, well, just do it ;).
def ExecuteOptionID(self, doc, plugid, subid): dlg = Options_Dlg() dlg.Open(c4d.DLG_TYPE_MODAL, *data) # Your dialog is modal, i.e. blocking, so this point will only # be reached once the dialog has been closed. # Reading out a gui value. self._some_int = dlg.GetInt32(ID_SOME_INT) # Or just reading out an attribute attached to the python object # of the dialog. self._some_data = dlg._the_answer_to_everything # You could of course also just make the options dialog itself # an attribute of your CommandData plugin. self._options = dlg # Although it would be probably better to do this on the # initialisation of the plugin, i.e. something like this: """ class MyPlugin (c4d.plugins.CommandData): ''' ''' def __init__(self): ''' Attach an instance of the options dialog to the instance of the CommandData plugin. ''' self._options_dlg = OptionsDialog() def ExecuteOptionID(self, doc, plugid, subid): ''' Just open the options dialog. ''' self._options_dlg.Open(c4d.DLG_TYPE_MODAL, *data) return True def some_function(*args, **kwargs): ''' Access some values in the dialog. ''' some_int = self._options_dlg.GetInt32(ID_SOME_INT) return some_int ** 2 """ return True
Cheers,
zipit -
@zipit Thank you for the reply.
I had several questions because I was confused. First was a request of an example of an Options dialog setup in a CommandData plugin as recommended by Maxon because I could not find one.
The rest of my questions just illustrate my confusion by the documentation: I don't understand if/how to use subid, ExecuteSubId, or GetSubContainer. I did not see any of those used in the example code you provided.
You said 'when you did override
CommandData.GetSubContainer
'...I don't think I did unless I am unaware. -
@blastframe said in CommandData ExecuteOptionID():
The rest of my questions just illustrate my confusion by the documentation: I don't understand if/how to use subid, ExecuteSubId, or GetSubContainer. I did not see any of those used in the example code you provided.
You said 'when you did override CommandData.GetSubContainer'...I don't think I did unless I am unaware.Hi,
sure, you did not. That was kind of my point. Sub IDs are only meaningful when you have split your command plugin into several sub commands, which you do 'initiate' by overriding
CommandData.GetSubContainer
. So the parametersubid
is only available, as the docs put it, when you did so, and reflects the sub command that is being executed by the user. If you did not define any sub commands, probably some value that indicates that unavailability, like-1
,0
orNone
, is being passed instead.Cheers,
zipit -
I'm not much clearer on the usage of
GetSubContainer
andsubid.
I still would greatly appreciate a code example of these if any of the SDK team would be so kind. Thanks! -
hi,
I'm on it, sorry for the delay. But i need to check if it's my being idiot or if it's not working as expected.
Having c++ examples will not hurt anybody.cheers,
Manuel -
@m_magalhaes Excellent, thank you very much!
-
hi,
i just saw that my answer wasn't clear on that thread and i didn't provided any feedback from my search..(really sorry for that)
It's a bug in the python API. (it's working as expected on c++)Cheers,
Manuel -
@m_magalhaes Just chiming in here... any news on those C++ examples?
Cheers,
Frank