THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/09/2011 at 04:44, xxxxxxxx wrote:
I'm trying to get my first plugin working and I am quite stuck on something that seemed easy to perform before I try it out.
Here is the problem. Basically I would like to encapsulate an xpresso setup into an objectdata plugin.
Here is my current code ( started from the rounded tube example in the documentation ) :
from c4d import plugins, utils, bitmaps, gui, documents
be sure to use a unique ID obtained from www.plugincafe.com
PLUGIN_ID = 1025250
class Softbox(plugins.ObjectData) :
def __init__(self) :
def Draw(self, op, drawpass, bd, bh) :
if drawpass == c4d.DRAWPASS_OBJECT: obj = self.\_softboxDocument.GetFirstObject() bd.SetMatrix_Matrix(obj, bh.GetMg()) #bd.SetPen(c4d.GetViewColor(c4d.VIEWCOLOR_SELECTION_PREVIEW)) #print obj.\__class\_\_.\__name\_\_ #bd.SetPen(c4d.GetViewColor(c4d.VIEWCOLOR_ACTIVEPOINT)) bd.DrawObject(bh, obj, c4d.DRAWOBJECT_0, drawpass, None) return c4d.DRAWRESULT_OK
def Init(self, op) :
res = True
dir, f = os.path.split(__file__)
file = os.path.join(dir, "", "softbox.c4d")
self._softboxDocument = documents.LoadDocument(file, c4d.SCENEFILTER_OBJECTS)
if self._softboxDocument is None:
res = false
def GetDimension(self, op, mp, rad) :
def MoveHandle(self, op, undo, tm, hitid, qualifier) :
def DetectHandle(self, op, bd, x, y, qualifier) :
def GetVirtualObjects(self, op, hierarchyhelp) :
#disabled cache because _optimize_cache was set to True
#dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTYFLAGS_DATA)
#if dirty is False: return op.GetCache(hierarchyhelp)
def SetAxis(obj, axis) :
if __name__ == "__main__":
dir, file = os.path.split(__file__)
icon = bitmaps.BaseBitmap()
icon.InitWith(os.path.join(dir, "res", "oroundedtube.tif"))
From what I experienced until now I have a few questions. First of all, I don't really understand the Init() method which seems to be called each time I'm clicking into the viewport ( I get the print's outputs for each click ). I thought that would be the method to load the content of the document containing my xpresso setup. What I tried to do here was to load this file, and display it into the viewport, without having all the setup into the object manager ( which is composed of a bit of geometry, many nodes and an xpresso rig with user datas to control things ). I wanted to load this setup from my plugin, and use the objectdata plugin as a messenger, just passing over datas to the xpresso setup, updating the setup and displaying the result into the viewport.
I only try for now to display an object which isnt in the scene, you can try using a sample scene containing only a cube placed next to the python script as softbox.c4d for tests.