Hello,
I have seen tag plugins that, when they are double-clicked, open a dialog.
Using the py-look_at_camera_r13 example from the SDK, I came up with the code below. I'm trying to open the Dialog with the Execute method of the plugin class which is clearly the wrong place for it.
import c4d, os
from c4d import plugins, utils, bitmaps, gui, documents
TAG_ID = 1234567
PLUGIN_ID = 2345678
global dlg
class MyDlg(gui.GeDialog):
def CreateLayout(self):
self.SetTitle("MyDlg")
self.GroupBegin(1, c4d.BFH_CENTER, 2, 1, None, 640)
self.GroupBorderSpace(10, 20, 10, 20)
self.AddButton(2, c4d.BFH_FIT, name="Yes", initw=100)
self.AddButton(3, c4d.BFH_FIT, name="No", initw=100)
self.GroupEnd()
return True
def Command(self, id, msg):
return True
class MyTagPlugin(c4d.plugins.TagData):
def Init(self, node):
pd = c4d.PriorityData()
if pd is None:
raise MemoryError("Failed to create a priority data.")
pd.SetPriorityValue(c4d.PRIORITYVALUE_CAMERADEPENDENT, True)
node[c4d.EXPRESSION_PRIORITY] = pd
return True
def Execute(self, tag, doc, op, bt, priority, flags):
global dlg
if dlg == None:
dlg = MyDlg()
dlg.Open(dlgtype=c4d.DLG_TYPE_ASYNC, xpos=-1, ypos=-1, pluginid=PLUGIN_ID, defaultw=540, defaulth=640)
return c4d.EXECUTIONRESULT_OK
if __name__ == "__main__":
# Retrieves the icon path
directory, _ = os.path.split(__file__)
fn = os.path.join(directory, "res", "icon.png")
# Creates a BaseBitmap
bmp = c4d.bitmaps.BaseBitmap()
if bmp is None:
raise MemoryError("Failed to create a BaseBitmap.")
# Init the BaseBitmap with the icon
if bmp.InitWith(fn)[0] != c4d.IMAGERESULT_OK:
raise MemoryError("Failed to initialize the BaseBitmap.")
c4d.plugins.RegisterTagPlugin(id=TAG_ID ,
str="MyTagPlugin",
info=c4d.TAG_EXPRESSION | c4d.TAG_VISIBLE,
g=MyTagPlugin,
description="Tmytagplugin",
icon=bmp)
This code throws the following error:
RuntimeError: illegal operation, invalid cross-thread call
I'm guessing it's because it's a gui call off of the main thread.
It seems the Tag plugins launch a Command Plugin somehow. I have a few questions about this:
- How would I launch the Command Plugin once when the tag is double-clicked and not every time Init() or Execute() are called by the tag or if one is already open?
- How could I get the Dialog Plugin to update its UI when one of the Python tag plugins is selected?
Thank you.