On 14/10/2014 at 12:23, xxxxxxxx wrote:
Here a working example thanks to Sebastian and the other Post posters, thanks.
One small issue: when the input value (the value to send taken from the input slider) that is send as p2, is zero (p2=0), I get the error:
TypeError: PyCObject_AsVoidPtr with non-Cobject.
The code below is for two command plugins nr1 and nr2.
Plugin nr2 sends specialevent to nr1 where is is received using CoreMessage and output into the dialog.
I made it in R15.
If you want the sources, send me a pm.
-Pim
Plugin nr:
import c4d
from c4d import gui, plugins, utils, bitmaps
import os
import sys
from ctypes import pythonapi, c_void_p, py_object
PLUGIN_ID1 = 1014874 #plugin nr1
PLUGIN_ID2 = 1014873 #plugin nr2
class MyDialog(gui.GeDialog) :
def CreateLayout(self) :
self.AddStaticText(id=1024, flags=c4d.BFH_LEFT, initw=150, name="Value to send", borderstyle=c4d.BORDER_NONE)
self.AddEditSlider(id=1025, flags=c4d.BFH_SCALEFIT, initw=70)
self.AddButton(1026, c4d.BFV_MASK, initw=100, name="Send to nr1")
return True
def Command(self, id, msg) :
if (id == 1026) :
print "self.GetInt32(1025) : ", self.GetInt32(1025)
c4d.SpecialEventAdd(PLUGIN_ID1, p1=PLUGIN_ID1, p2=self.GetInt32(1025))
return True
return True
class PluginNr2(plugins.CommandData) :
dialog = None
def Execute(self, doc) :
# create the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID2, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
def RestoreLayout(self, sec_ref) :
# manage the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Restore(pluginid=PLUGIN_ID2, secret=sec_ref)
if __name__ == "__main__":
path, fn = os.path.split(__file__)
bmp = bitmaps.BaseBitmap() #We need an instance of BaseBitmap class to use an image
bmp.InitWith(os.path.join(path, "res/icons/", "icon.tif")) #The location where the menu image exists
plugins.RegisterCommandPlugin(PLUGIN_ID2, "Plugin r15 nr2",0, bmp, "Plugin r15 nr2", PluginNr2())
Plugin nr1:
import c4d
from c4d import gui, plugins, utils, bitmaps
import os
from ctypes import pythonapi, c_void_p, py_object
PLUGIN_ID1 = 1014874 #plugin nr1
PLUGIN_ID2 = 1014873 #plugin nr2
class MyDialog(gui.GeDialog) :
def CreateLayout(self) :
self.AddStaticText(id=1024, flags=c4d.BFH_LEFT, initw=150, name="Value received", borderstyle=c4d.BORDER_NONE)
self.AddEditNumber(id=1025, flags=c4d.BFH_SCALEFIT, initw=70)
return True
def Command(self, id, msg) :
return True
def CoreMessage(self, id, msg) :
if id == PLUGIN_ID1:
# Get the Void Container
P1MSG_UN = msg.GetVoid(c4d.BFM_CORE_PAR1)
# Get the actual data (This is beyond my knowledge but it works!)
pythonapi.PyCObject_AsVoidPtr.restype = c_void_p
pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
P1MSG_EN = pythonapi.PyCObject_AsVoidPtr(P1MSG_UN)
P2MSG_UN = msg.GetVoid(c4d.BFM_CORE_PAR2)
pythonapi.PyCObject_AsVoidPtr.restype = c_void_p
pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]
P2MSG_EN = pythonapi.PyCObject_AsVoidPtr(P2MSG_UN)
print "Data received CoreMessage in MyDialog: ", P1MSG_EN, P2MSG_EN
self.SetInt32(1025, P2MSG_EN)
return True
class PluginNr1(plugins.CommandData) :
dialog = None
def Execute(self, doc) :
# create the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=PLUGIN_ID1, defaultw=200, defaulth=150, xpos=-1, ypos=-1)
def RestoreLayout(self, sec_ref) :
# manage the dialog
if self.dialog is None:
self.dialog = MyDialog()
return self.dialog.Restore(pluginid=PLUGIN_ID1, secret=sec_ref)
if __name__ == "__main__":
path, fn = os.path.split(__file__)
bmp = bitmaps.BaseBitmap() #We need an instance of BaseBitmap class to use an image
bmp.InitWith(os.path.join(path, "res/icons/", "icon.tif")) #The location where the menu image exists
plugins.RegisterCommandPlugin(PLUGIN_ID1, "Plugin r15 nr1",0, bmp, "Plugin r15 nr1", PluginNr1())