On 26/04/2013 at 08:01, xxxxxxxx wrote:
This is my first try at a ObjectData plugin, after reading a lot of posts on this subject.
It generates a simple sweepNURBS, the path spline should be a child of the plugin.
The contour is created in the plugin.
Everything seems ok the first time.
Except, when I replace the path spline, the sweep NURBS it is not refreshed / updated?
I added my own CheckDirty, but it is never called (no logging).
What am I missing?
Here is the complete code.
import os
import math
import sys
import c4d
from c4d import plugins, utils, bitmaps, gui
PLUGIN_ID = 10252501
class SweepObj(plugins.ObjectData) :
def __init__(self) :
self.SetOptimizeCache(True)
def CheckDirty(self, op, doc) :
print "CheckDirty."
op.SetDirty(c4d.DIRTYFLAGS_DATA)
def GetVirtualObjects(self, op, hierarchyhelp) :
print "GetVirtualObjects."
# Disabled the following lines because cache flag was set
# So the cache build is done before this method is called
#dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
#if dirty is False: return op.GetCache(hierarchyhelp)
#Get the child / parent object (to use as the sweep spline)
#Use GetClone so we aren't working on the object itself
source = op.GetDown()
if (source is None) : return None
#upsource = op.GetUp()
#if (upsource is None) : return None
source = op.GetDown().GetClone()
#source = op.GetUp().GetClone(c4d.COPYFLAGS_NO_HIERARCHY)
#Create a Circle Primitive to act as the sweep profile
circle = c4d.BaseObject(c4d.Osplinecircle)
#Set the radius
circle[c4d.PRIM_CIRCLE_RADIUS] = 10.0
#Create a new SweepNURBS
sweep = c4d.BaseObject(c4d.Osweep)
#Insert the source sweep spline under the SweepNURBS
source.InsertUnder(sweep)
#Insert the circle profile spline under the SweepNURBS
circle.InsertUnder(sweep)
#sweep.Message (c4d.MSG_UPDATE) #update sweep in viewport
#c4d.EventAdd()
#Return the SweepNURBS
return sweep
if __name__ == "__main__":
pluginstr = "SweepObj v01"
dir, file = os.path.split(__file__)
icon = bitmaps.BaseBitmap()
icon.InitWith(os.path.join(dir, "res", "sweepobj.tif"))
okyn = plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="SweepObj",
g=SweepObj,
description="SweepObj", icon=icon,
info=c4d.OBJECT_GENERATOR)
if (okyn) :
print pluginstr + " initialized."
else: print "Error initializing " + pluginstr