Render Nothing!why? [SOLVED]
-
On 07/02/2017 at 17:21, xxxxxxxx wrote:
Hello,
I'm learning to create a plugin form internet,but render nothing,why? and the Traceback below:
Traceback (most recent call last) :
File "'test.pyp'", line 49, in GetVirtualObjectsReferenceError: the host object of 'c4d.BaseContainer' is not alive
Here is the code downloaded form internet below:
import c4d import os import sys from c4d import plugins, utils, bitmaps PLUGIN_ID = 123456789 BU_DATA = 1000 REAL_HEIGHT = 1001 REAL_DEPTH = 1002 REAL_WIDTH = 1003 REAL_KICH_HEIGHT = 1004 REAL_KICH_DEPTH = 1005 REAL_THICKNESS = 1006 class testData(plugins.ObjectData) : def Init(self, node) : self.data = node.GetDataInstance() self.data.SetReal(c4d.REAL_HEIGHT,92.0) self.data.SetReal(c4d.REAL_DEPTH,65.0) self.data.SetReal(c4d.REAL_WIDTH,70.0) self.data.SetReal(c4d.REAL_KICH_HEIGHT,10.0) self.data.SetReal(c4d.REAL_KICH_DEPTH,10.0) self.data.SetReal(c4d.REAL_THICKNESS,2.0) return True def Message(self, node, type, data) : if type == c4d.MSG_DESCRIPTION_COMMAND: if data["id"][0].id == BU_DATA: #print "Hello World" return True def Execute(self, op, doc, bt, priority, flags) : return True def GetVirtualObjects(self, op, hh) : dirty = op.CheckCache(hh) or op.IsDirty(c4d.DIRTY_DATA) if dirty is False: return op.GetCache(hh) L_Height = self.data.GetReal(c4d.REAL_HEIGHT) L_Depth = self.data.GetReal(c4d.REAL_DEPTH) L_Kick_Height = self.data.GetReal(c4d.REAL_KICK_HEIGHT) L_Kick_Depth = self.data.GetReal(c4d.REAL_KICK_Depth) L_Width = self.data.GetReal(c4d.REAL_WIDTH) L_Thickness = self.data.GetReal(c4d.REAL_THICKNESS) null = c4d.BaseObject(c4d.Onull) ex = c4d.BaseObject(Oextrude) ex[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,0,L_Thickness) extop = c4d.BaseObject(Oextrude) extop[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,3,0) exdaw = c4d.BaseObject(Oextrude) exdaw[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,L_Thickness,0) exfro = c4d.BaseObject(Oextrude) exfro[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(-L_Thickness,0,0) exba = c4d.BaseObject(Oextrude) exba[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(L_Thickness,0,0) exdoor = c4d.BaseObject(Oextrude) exdoor[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(L_Thickness,0,0) exins = c4d.BaseObject(Oextrude) exins[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0,0,-L_Thickness) ins = c4d.BaseObject(Oinstance) ins[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z] = L_Width sp = c4d.SplineObject(6,6) sp1 = c4d.SplineObject(4,4) sp2 = c4d.SplineObject(4,4) sp3 = c4d.SplineObject(4,4) sp4 = c4d.SplineObject(4,4) sp5 = c4d.SplineObject(4,4) sp.SetPoint(0,c4d.Vector(0,0,0)) sp.SetPoint(1,c4d.Vector(0,L_Height,0)) sp.SetPoint(2,c4d.Vector(L_Depth,L_Height,0)) sp.SetPoint(3,c4d.Vector(L_Depth,L_Kich_Height,0)) sp.SetPoint(4,c4d.Vector(L_Depth-L_Kich_Depth,L_Kich_Height,0)) sp.SetPoint(5,c4d.Vector(L_Depth-L_Kich_Depth,0,0)) sp[c4d.SPLINEOBJECT_TYPE] = 0 sp[c4d.SPLINEOBJECT_CLOSED] = True sp.Message(c4d.MSG_UPDATE) ins[c4d.INSTANCEOBJECT_LINK] = sp sp1.SetPoint(0,c4d.Vector(0,L_Height,0)) sp1.SetPoint(1,c4d.Vector(0,L_Height,L_Width)) sp1.SetPoint(2,c4d.Vector(L_Depth+5,L_Height,L_Width)) sp1.SetPoint(3,c4d.Vector(L_Depth+5,L_Height,0)) sp1[c4d.SPLINEOBJECT_TYPE] = 0 sp1[c4d.SPLINEOBJECT_CLOSED] = True sp2.SetPoint(0,c4d.Vector(L_Thickness,L_Kich_Height,L_Thickness)) sp2.SetPoint(1,c4d.Vector(L_Thickness,L_Kich_Height,L_Width-L_Thickness)) sp2.SetPoint(2,c4d.Vector(L_Depth,L_Kich_Height,L_Width-L_Thickness)) sp2.SetPoint(3,c4d.Vector(L_Depth,L_Kich_Height,L_Thickness)) sp2[c4d.SPLINEOBJECT_TYPE] = 0 sp2[c4d.SPLINEOBJECT_CLOSED] = True sp3.SetPoint(0,c4d.Vector(L_Depth-L_Kick_Depth-L_Thickness,0,L_Thickness)) sp3.SetPoint(1,c4d.Vector(L_Depth-L_Kick_Depth-L_Thickness,L_Kich_Height,L_Thickness)) sp3.SetPoint(2,c4d.Vector(L_Depth-L_Kick_Depth-L_Thickness,L_Kich_Height,L_Width- L_Thickness)) sp3.SetPoint(3,c4d.Vector(L_Depth-L_Kick_Depth-L_Thickness,0,L_Width-L_Thickness)) sp3[c4d.SPLINEOBJECT_TYPE] = 0 sp3[c4d.SPLINEOBJECT_CLOSED] = True sp4.SetPoint(0,c4d.Vector(0,0,L_Thickness)) sp4.SetPoint(1,c4d.Vector(0,L_Height,L_Thickness)) sp4.SetPoint(2,c4d.Vector(0,L_Height,L_Width-L_Thickness)) sp4.SetPoint(3,c4d.Vector(0,0,L_Width-L_Thickness)) sp4[c4d.SPLINEOBJECT_TYPE] = 0 sp4[c4d.SPLINEOBJECT_CLOSED] = True sp5.SetPoint(0,c4d.Vector(L_Depth+0.3,L_Kich_Height,0)) sp5.SetPoint(1,c4d.Vector(L_Depth+0.3,L_Height,0)) sp5.SetPoint(2,c4d.Vector(L_Depth+0.3,L_Height,L_Width)) sp5.SetPoint(3,c4d.Vector(L_Depth+0.3,L_Kich_Height,L_Width)) sp5[c4d.SPLINEOBJECT_TYPE] = 0 sp5[c4d.SPLINEOBJECT_CLOSED] = True sp.InsertUnder(ex) sp1.InsertUnder(extop) sp2.InsertUnder(exdaw) sp3.InsertUnder(exfro) sp4.InsertUnder(exba) sp5.InsertUnder(exdoor) ex.InsertUnder(null) exins.InsertUnder(null) extop.InsertUnder(null) exdaw.InsertUnder(null) exfro.InsertUnder(null) exba.InsertUnder(null) exdoor.InsertUnder(null) ins.InsertUnder(exins) c4d.EventAdd() return null if __name__ == '__main__': path, file = os.path.split(__file__) bmp = bitmaps.BaseBitmap() bmp.InitWith(os.path.join(path, "res", "icon", "icon.tif")) plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="test", g=testData, description="Otest", icon=bmp, info=c4d.OBJECT_GENERATOR|c4d.OBJECT_ISSPLINE)
Edit Andreas: Added code tags (please see
BBcodes
[URL-REMOVED], link below edit field) and moved to Python sub-forum
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 08/02/2017 at 02:37, xxxxxxxx wrote:
Hi,
in the end it's not rendering, because of the error you get shown on the Console and the error is actually hinting into the correct direction.
In Init() you are storing the reference to the node's BaseContainer in a member variable. You should not do this. The node will be copied on several occasions (e.g. when cloning the document for rendering purposes) and in your case this will lead to either a stale reference or no reference at all in that member variable. You could try to handle this in CopyTo(), but I strongly discourage to do so.
Instead simply get the correct BaseContainer instance in GVO.Furthermore:
It's not needed to call EventAdd() in GVO, actually you must not use EventAdd() in GVO. See it like this: In GVO you are creating a new object (or object hierarchy), nothing in the scene depends on at this point in time (the new object is not yet part of the document), so there's no need to notify any entity in the scene about a change. -
On 11/02/2017 at 01:55, xxxxxxxx wrote:
Hi,Andreas.
Thank you!