BaseDraw::DrawObject
-
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:
Hi everyone,
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 ) :
import os
import c4dfrom 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) :
self.SetOptimizeCache(True)
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)
print op.GetMg()
print self._softboxDocument.GetFirstObject().GetMg()
if self._softboxDocument is None:
res = false
print res
return res
def GetDimension(self, op, mp, rad) :
passdef MoveHandle(self, op, undo, tm, hitid, qualifier) :
return Truedef DetectHandle(self, op, bd, x, y, qualifier) :
return 3def 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)
pass@staticmethod
def SetAxis(obj, axis) :
passif __name__ == "__main__":
dir, file = os.path.split(__file__)
icon = bitmaps.BaseBitmap()
icon.InitWith(os.path.join(dir, "res", "oroundedtube.tif"))
plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="Py-RoundedTube",
g=Softbox,
description="roundedtube", icon=icon,
info=c4d.OBJECT_GENERATOR)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.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/09/2011 at 07:14, xxxxxxxx wrote:
Hi again, here is a little update of my try.
By following the code of rounded tube I could get my mesh displayed by returning the object I wanted to show in the viewport in the method GetVirtualObjects().
But, I still don't get what is this method for. I had a look at the documentation and it is really not clear.
Here is my method :
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)
distance = op[c4d.PY_TUBEOBJECT_RAD];obj = self.\_softboxDocument.GetFirstObject() obj[c4d.ID_USERDATA, 8] = distance obj.Message(c4d.MSG_UPDATE) obj.Touch() print obj[c4d.ID_USERDATA, 8] return obj
This object that I load in Init() from another .c4d contains some user datas that I would like to feed from my plugin objectdata and see the update in the viewport, those user datas are connected to an xpresso tag. Note that I kept the basic interface of rounded tube for test purposes and tried to redirect the radius to the "distance" user data of my loaded object. Which is ID 8. But nothing happens in the viewport.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 11/09/2011 at 10:12, xxxxxxxx wrote:
Last note, when I try to make the object data editable, I get the whole xpresso setup being imported into the object manager. And, the distance is set properly and the viewport is finally updated with everything at the right position, it seems I cannot get the xpresso being executed when I modify the user datas feeding this xpresso. If anyone got an idea.