Setting up ObjectData plugin priority in Python
-
Apologies if this has been answered before, but I could not find it by searching.
my plugin makes a null follow the matrix of another object. problem is that because of priorities unless the plugin object is after the "target" it is always one frame behind ( or it snaps on position when you refresh the viewport)
my plugin is based on ObjectData, and is a Generator, not a tag, so how do I go about changing the priority so that the code only runs after the target's matrix has been calculated?
i'd much appreciate a "dummies" explanation, as I am still only dipping my toes into programming and plugin dev
Many thanks,
Eddie -
Hi,
while object nodes (i.e.
ObjectData
) also have a priority list, it is AFAIK only being used to determine the call order ofObjectData.Execute
and not the order of any cache building. What you could do is:- Flag your
ObjectData
plugin asOBJECT_INPUT
on registration. This should ensure that Cinema does evaluate its children first. - Manually evaluate the object you want to depend on. This could range from mildly expensive (a) to ridiculously expensive (b):
a. Clone the object you want to evaluate and insert it into a temporary document, set the temporary document time to the time of the active document and execute all passes on the temporary document and finally retrieve your object.
b. Clone the whole document, execute its passes and retrieve your object. - Your general approach is also rather unusual. Normally you do not bake the world position of something else into the cache of a
BaseObject
. A more common architecture would be to implement anObjectData
plugin that generates whatever cache you to generate and then aTagData
plugin that does the "sticking to an object's world position"-part (or just use one of Cinema's existing constraint tags). Note that the tag would have to be attached to yourBaseObject
node, not its cache, since caches are not being evaluated for expressions.
Cheers,
zipit - Flag your
-
Hi @Eduardo-Oliveira first of all welcome on the PluginCafe community.
I think @zipit already provided you some correct answers or at least point you that this workflow is kind of strange for a Cinema 4D user since normally the object by itself doesn't really set its own position, but it's up to a tag (constraint Tag) to define the object position to another one.
But in case you really want to do it, doing it in the Execute method of your ObjectData is fine.
def AddToExecution(self, op, list): list.Add(op, c4d.EXECUTIONPRIORITY_GENERATOR, c4d.EXECUTIONFLAGS_CACHEBUILDING) return True def Execute(self, op, doc, bt, priority, flags): op.SetMg(doc.GetFirstObject().GetMg()) return c4d.EXECUTIONRESULT_OK
You also need to ensure you registered your object with the flag c4d.OBJECT_CALL_ADDEXECUTION so AddToExecution and Execute are called.
Cheers,
Maxime.