On 26/06/2018 at 06:24, xxxxxxxx wrote:
Hi Faxwang,
Regarding your issue, the main problem is that you use a link to another object.
So that means you have to listen for a change in this object to be able to say to your modifier to update. But you also need to listen for the current matrix of the modified object.
And that's the perfect purpose of CheckDirty.
Another thing, self.SetOptimizeCache(True) is only used for Generator, and not a modifier.
Another good practise is to make sure to define your constants (c4d.OBJECT / MAP) with a custom prefix in order to be sure there is no ID collision.
I also rework your algorithm in order to not need an Up object.
class test(plugins.ObjectData) :
targetObj = None
targetObjLastMg = None
currentObj = None
currentObjLastMg = None
def CheckDirty(self, op, doc) :
# Check if modified object is not already define (aka first execution of the Modifier)
if self.currentObj is None:
op.SetDirty(c4d.DIRTYFLAGS_DATA)
return
# Check if the matrice of the modified object is dirty or not, in order to update the modifier
if self.currentObj.GetMg() != self.currentObjLastMg:
# We tell to our Modifier something has change which will trigger the call of ModifyObject
op.SetDirty(c4d.DIRTYFLAGS_DATA)
return
# Check if targetObj exist
if self.targetObj:
# Check if targetObj is still alive, and the Position we have store is changed.
if self.targetObj.IsAlive() and self.targetObj.GetMg() != self.targetObjLastMg:
# We tell to our Modifier something has change which will trigger the call of ModifyObject
op.SetDirty(c4d.DIRTYFLAGS_DATA)
return
return
def ModifyObject(self, mod, doc, op, op_mg, mod_mg, lod, flags, thread) :
if not mod[1000] or not mod[1001]:
return True
pts = op.GetAllPoints()
self.currentObj = mod
self.currentObjLastMg = mod.GetMg()
self.targetObj = mod[1000]
self.targetObjLastMg = self.targetObj.GetMg()
targetGlobalPos = self.targetObjLastMg.off
vex = mod[1001].GetAllHighlevelData()
cnt = len(vex)
for i in xrange(cnt) :
if vex[i]:
currentGlobalPos = pts[i] * op.GetMg()
distancePosWeighted = (targetGlobalPos - currentGlobalPos) * vex[i]
finalLocalPos = pts[i] + distancePosWeighted
op.SetPoint(i, finalLocalPos)
op.Message(c4d.MSG_UPDATE)
return True
Another thing, please use [ code] and [ /code] when you post code on the forum which makes it easier to read 
If you have any questions, feel free to ask.
Cheers,
Maxime