On 07/08/2015 at 11:58, xxxxxxxx wrote:
Hi,
I'm still pretty green with both C4D and Python, but I'm attempting to build a simple velocity/acceleration script that I could store in a Tag. I have a mathematical approximation for the velocity/accel based on two/three points of position, respectively. My hang-up is trying to retrieve an object's position when it is not driven by keys or curves directly (i.e. if it is driven by Xpresso or contained in an animated Null).
It may just be a gap in my understanding, but I've only been able to successfully retrieve an object's position at different points in time by moving the playhead and updating the viewport. So my question is: _ Is it possible to _ get the position of a non-self-animated object without having to scrub the timeline?
Here's a sample of what I am currently doing (moving the playhead via Python, and updating timeline. I've gotten the flags/method from the posts of others, so please let me know if I can do this better!)
dvFlag1 = c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW #Only redraw the active view
dvFlag2 = c4d.DRAWFLAGS_NO_THREAD #Synchronous call
dvFlag3 = c4d.DRAWFLAGS_NO_REDUCTION #Ignore the redraw limit
dvFlag4 = c4d.DRAWFLAGS_STATICBREAK #Used to poll ESC key for NO_THREAD
pos = []
pos.append(animObj.GetRelPos()) #Record the object's current position
doc.SetTime(c4d.BaseTime(prevFrame, FPS)) #Move to the defined prevFrame frame value
c4d.DrawViews(dvFlag1|dvFlag2|dvFlag3|dvFlag4) #Redraw the veiwport with flags defined above
c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) #SyncMessage to C4D to update timeline
pos.append(animObj.GetRelPos()) #Record the object's relative position
doc.SetTime(c4d.BaseTime(nextFrame, FPS)) #Move to the defined nextFrame frame value
c4d.DrawViews(dvFlag1|dvFlag2|dvFlag3|dvFlag4) #Redraw the veiwport with flags defined above
c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) #SyncMessage to C4D to update timeline
pos.append(animObj.GetRelPos()) #Record the object's relative position
doc.SetTime(c4d.BaseTime(cFrame, FPS)) #Move playhead back to current frame
In a perfect world, the values would continuously update in some User Data fields on the tag as I preview an animation--but I'd obviously run into issues if I want to both play-back the animation AND need to have Python jump back and forth to retrieve position values.
Any help or thoughts are greatly appreciated!
Marcus