Communication between ToolData and SubDialog
-
On 20/12/2015 at 09:47, xxxxxxxx wrote:
Hello everbody,
in the following purified ToolDataCode two number fields of the subdialog are live-updated with the current mouse position (x,y) by the ToolData... if the mouse is over the editor, of course. After some attempts Ive found the setter-way. So thats fine.
Now I want the position of a drawn circle live-updated by these two number fields, but I have no ideas how to call the tooldata from the subdialog.Any ideas?
import c4d import os import math from math import pi as pi from c4d import gui, plugins, bitmaps #be sure to use a unique ID obtained from www.plugincafe.com PLUGIN_ID = 548721 class SettingsDialog(gui.SubDialog) : def __init__(self, arg) : self.opts = arg def CreateLayout(self) : self.GroupBegin(10000, c4d.BFH_LEFT, 2, 1) self.GroupBorderSpace(5,5,5,5) self.AddStaticText(10001, c4d.BFH_LEFT, initw=100, inith=0, name='Mouse X') self.AddEditNumberArrows(10002, c4d.BFH_MASK, initw=100, inith=0) self.AddStaticText(10003, c4d.BFH_LEFT, initw=100, inith=0, name='Mouse Y') self.AddEditNumberArrows(10004, c4d.BFH_MASK, initw=100, inith=0) self.GroupEnd() return True def InitValues(self) : self.SetLong(10002, self.opts["x"]) self.SetLong(10004, self.opts["y"]) return True def SetMousePosition(self, x, y) : self.opts['x'] = x self.opts['y'] = x self.SetLong(10002, x) self.SetLong(10004, y) def Command(self, id, msg) : if id==10002: self.opts["x"] = self.GetLong(10002) if id==10004: self.opts["y"] = self.GetLong(10004) return True class TDTest(plugins.ToolData) : x = y = 0 subdialog = None def __init__(self) : self.data = dict(x=0, y=0) def Draw(self, doc, data, bd, bh, bt, flags) : bd.SetPen(c4d.Vector(1,1,1)) bd.DrawHandle2D(c4d.Vector(self.x,self.y,0), c4d.DRAWHANDLE_BIG) bd.DrawCircle2D(self.x, self.y, 20) return c4d.TOOLDRAW_HANDLES|c4d.TOOLDRAW_AXIS def GetCursorInfo(self, doc, data, bd, x, y, bc) : print x,y if x!=-1 and y!=-1: self.x = int(x) self.y = int(y) if self.subdialog: self.subdialog.SetMousePosition(self.x, self.y) c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION) return True def AllocSubDialog(self, bc) : self.subdialog = SettingsDialog(self.data) return self.subdialog #always return new instance if __name__ == "__main__": bmp = bitmaps.BaseBitmap() dir, file = os.path.split(__file__) fn = os.path.join(dir, "res", "") bmp.InitWith(fn) plugins.RegisterToolPlugin(id=PLUGIN_ID, str="TDTest", info=c4d.PLUGINFLAG_TOOL_HIGHLIGHT|c4d.PLUGINFLAG_TOOL_SNAPSETTINGS, icon=bmp, help="This string is shown in the statusbar", dat=TDTest())
greetings
rown -
On 20/12/2015 at 10:21, xxxxxxxx wrote:
Ok, sorry for open new topic... Ive solved my trouble.
import c4d import os import math from math import pi as pi from c4d import gui, plugins, bitmaps #be sure to use a unique ID obtained from www.plugincafe.com PLUGIN_ID = 548721 class SettingsDialog(gui.SubDialog) : def __init__(self, arg) : self.opts = arg def CreateLayout(self) : self.GroupBegin(10000, c4d.BFH_LEFT, 2, 1) self.GroupBorderSpace(5,5,5,5) self.AddStaticText(10001, c4d.BFH_LEFT, initw=100, inith=0, name='Mouse X') self.AddEditNumberArrows(10002, c4d.BFH_MASK, initw=100, inith=0) self.AddStaticText(10003, c4d.BFH_LEFT, initw=100, inith=0, name='Mouse Y') self.AddEditNumberArrows(10004, c4d.BFH_MASK, initw=100, inith=0) self.GroupEnd() return True def InitValues(self) : self.SetLong(10002, self.opts["x"]) self.SetLong(10004, self.opts["y"]) return True def SetMousePosition(self, x, y) : self.opts['x'] = x self.opts['y'] = y self.SetLong(10002, x) self.SetLong(10004, y) def Command(self, id, msg) : if id in (10002,10004) : self.opts["x"] = self.GetLong(10002) self.opts["y"] = self.GetLong(10004) c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION) return True class TDTest(plugins.ToolData) : subdialog = None def __init__(self) : self.data = dict(x=0, y=0) def Draw(self, doc, data, bd, bh, bt, flags) : bd.SetPen(c4d.Vector(1,1,1)) bd.DrawHandle2D(c4d.Vector(self.data['x'],self.data['y'],0), c4d.DRAWHANDLE_BIG) bd.DrawCircle2D(self.data['x'], self.data['y'], 20) return c4d.TOOLDRAW_HANDLES|c4d.TOOLDRAW_AXIS def GetCursorInfo(self, doc, data, bd, x, y, bc) : if x!=-1 and y!=-1: self.data['x'] = int(x) self.data['y'] = int(y) if self.subdialog: self.subdialog.SetMousePosition(self.data['x'], self.data['y']) c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION) return True def AllocSubDialog(self, bc) : self.subdialog = SettingsDialog(self.data) return self.subdialog #always return new instance if __name__ == "__main__": bmp = bitmaps.BaseBitmap() dir, file = os.path.split(__file__) fn = os.path.join(dir, "res", "") bmp.InitWith(fn) plugins.RegisterToolPlugin(id=PLUGIN_ID, str="TDTest", info=c4d.PLUGINFLAG_TOOL_HIGHLIGHT|c4d.PLUGINFLAG_TOOL_SNAPSETTINGS, icon=bmp, help="This string is shown in the statusbar", dat=TDTest())
I just add c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION) to the CommandMethod and the position is now written directly into the dictionary.