Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > PYTHON Development
  New Posts New Posts
  FAQ FAQ  Forum Search

Python in the context of CMotion

Author
Message
  Topic Search Topic Search
NNenov View Drop Down
Member
Member
Avatar

Joined: 2016 Apr 26
Location: UK
Online Status: Offline
Posts: 69
Direct Link To This Post Topic: Python in the context of CMotion
    Posted: 2018 Aug 25 at 7:45am
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?



Edited by NNenov - 2018 Aug 25 at 8:39am
Back to Top
MaximeA View Drop Down
Forum Moderator
Forum Moderator

Forum Moderator

Joined: 2018 Jan 04
Location: France - Nantes
Online Status: Offline
Posts: 119
Direct Link To This Post Posted: 2018 Aug 27 at 9:01am
Hi Nnenov,

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!
Cheers,
Maxime.
MAXON
SDK Specialist
Back to Top
NNenov View Drop Down
Member
Member
Avatar

Joined: 2016 Apr 26
Location: UK
Online Status: Offline
Posts: 69
Direct Link To This Post Posted: 2018 Aug 27 at 7:44pm
Hi Maxime,
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

Thanks again!
Nick
Back to Top
MaximeA View Drop Down
Forum Moderator
Forum Moderator

Forum Moderator

Joined: 2018 Jan 04
Location: France - Nantes
Online Status: Offline
Posts: 119
Direct Link To This Post Posted: 2018 Aug 28 at 3:22am
Hi,

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.

Cheers,
Maxime.
MAXON
SDK Specialist
Back to Top
NNenov View Drop Down
Member
Member
Avatar

Joined: 2016 Apr 26
Location: UK
Online Status: Offline
Posts: 69
Direct Link To This Post Posted: 2018 Aug 28 at 7:42pm
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
Thanks!
Back to Top

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.