On 09/04/2015 at 07:07, xxxxxxxx wrote:
Hi Pim, Hi Yannick
@Pim
The problem with the IsDirty() function and a generator object is, that IsDirty() seems to be hierarchy dependent.
Within your child structure this might be possible, but with a link field where the object can be anywhere in the hierarchy your example wont work. Anyway, thanks for your effort.
@Yannick
Thanks for the hints and lines!
Originally posted by xxxxxxxx
To prevent errors in GetLink() you should check if the user data exists and if it's really a link:
Thinking further about what could happen in the worst case, I figured out that there is even another case I need to cover.
if not link.IsInstanceOf(c4d.Opolygon) :link = link.GetCache()
This line produces an error if the linked atom is a material. I used try except...
Another problem occured!
If the linked object is a primitiv, the dirty check only triggers once and after that the generator wont update anymore.
Could you please tell me what´s wrong with the code?
import c4d, random
from c4d import utils,gui
global dcount
dcount = 0
def GetLink(op) :
udOK = False
for udID, udBC in op.GetUserDataContainer() :
if udID[1].id==1 and udID[1].dtype==c4d.DTYPE_BASELISTLINK:
udOK = True
break
if not udOK:
dialog=gui.MessageDialog("No appropriate UserData available! \n"
"Please insert a linkfield \n"
"and activate the generator again.",c4d.GEMB_OK)
op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = False
return
link = op[c4d.ID_USERDATA,1]
if not link: return
if not link.IsInstanceOf(c4d.Opolygon) :
try:
link = link.GetCache()
except: return
deform = link.GetDeformCache()
if deform:
link = deform
return link
def main() :
global dcount
if op[c4d.OPYTHON_OPTIMIZE] == True:
dialog=gui.MessageDialog("Please uncheck Optimize Cache! \n"
"and activate the generator again.",c4d.GEMB_OK)
op[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = False
return
vor = GetLink(op)
if not vor:return
#_____________________________________________________
#custom dirty test with linked object
vdirty = vor.GetDirty(c4d.DIRTY_DATA|c4d.DIRTY_MATRIX)
if vdirty:
if dcount != vdirty:
print "dirty"
dcount = vdirty
op.SetDirty(c4d.DIRTY_DATA|c4d.DIRTY_MATRIX)
if not op.IsDirty(c4d.DIRTY_DATA|c4d.DIRTY_MATRIX) :return op.GetCache()
#_____________________________________________________
#parent virtual object
null = c4d.BaseObject(c4d.Onull)
child = vor.GetClone()
#child.SetMg(op.GetMg())
child.InsertUnder(null)
return null
Thanks in advance !
Best wishes
Martin