Python in the context of CMotion
On 25/08/2018 at 07:45, xxxxxxxx wrote:
I'm digging around some areas of c4d which I've neglected for a while, today its the CMotion object.
Does anyone know of any examples or use cases for python in the context of CMotion actions? Does it have some predefined parameters/variables? in the help file it just says
"You can write, copy, paste, etc.. your Python scripts in this input field. They will be executed automatically by CMotion once the animation is run."
So I assume there must be some method of addressing relevant / relative cmotion properties?
On 27/08/2018 at 09:01, xxxxxxxx wrote:
Regarding your question, you have to define a function called Action.
Then there is some globals variable available.
doc: BaseDocument - The document of the current Cmotion Object.
op: BaseList2D - The object affected by this python Cmotion action.
time: float - The time in the current document.
cycle: float - Count of cycle already occurs (for example if the Cmotion Time is set to 30F, it's basically int(CurrentFrame)/int(30))
pos: float - Current time position in the cycle (from 0.0 to 1.0)
phase: float - Current value of the phase.
weight: float - The weight of the python Cmotion action.
Here a basic example about how to move an object in the X direction.
import c4d def Action() : maxXValue = 100 * weight op.SetRelPos(c4d.Vector(maxXValue,0 ,0) * pos)
If you have any question please let me know!
On 27/08/2018 at 19:44, xxxxxxxx wrote:
Thanks, this is great!
I was wondering, is there a way to get other objects in the list, for example if op is the object affected by the action, is there a way to relatively (or absolutely) reference another object in the CMotion object manager?
e.g. I tried op.GetNext() but it doesn't seem to work
On 28/08/2018 at 03:22, xxxxxxxx wrote:
I'm afraid it's not possible, op is just a link to the actual object within the scene.
And there is no way to find the corresponding Cmotion Object, and even if you get the Cmotion Object, CMotion[c4d.ID_CA_WCYCLE_TAG_OBJECTS] is currently not exposed in python and you can't iterate the tree.
On 28/08/2018 at 19:42, xxxxxxxx wrote:
Aw well, I'm not sure what I want to do yet anyway. If I wanted I can just reference the parameters being affected directly from the objects in my scene, I think. need to play with it more