THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/02/2011 at 15:34, xxxxxxxx wrote:
Originally posted by xxxxxxxx
So far I can only get key values on one track.
Yes. The python example I posted only loops though all the keys on a single track using a for loop.
In order to get the keys on the other tracks. That for loop would need to be inside of a while loop to move on to the next track. which isn't that difficult to do.
The hard part is that you have to get the last key first as you loop through all of this stuff. Because if you move the first keys in order. They will end up on top of eachother. And the loop will fail.
Think of a train pulling it's cargo cars.
The code in Coffee to do that looks like this: for(i=curve->GetKeyCount()-1; i>=0 ; --i)
Which means. Start from the last key. Then work your way back every time the loop runs.
I don't know how to write that kind of loop in python yet.
Originally posted by xxxxxxxx
And the selection of key seems to depend on the object selection, rather than just a key selection
Confused - but learning as I go. Thanks again to all
Sort of. It's a case of Parent ->Child relationships.
The document is the parent of all objects. So to get at objects in python you write doc.GetActiveObject(). Where doc is the parent, and the selected object is the child.
The same rule goes for things attached to objects.
-Tracks are the children of objects.
--Curves are the children of tracks
---Keys are the children of curves.
So you almost never grab things directly in C4D. You get the parent. Then drill down into it's children until you reach the item you want to manipulate.
Hope that makes sense.
-ScottA
Edit* - I just found this with Google. Turns out it's not as hard to do a revese loop in python as I thought. In fact it's pretty darned simple:
cnt = curve.GetKeyCount()
for i in reversed(xrange(cnt)) :
keys = curve.GetKey(i)
if keys.GetNBit(5) is 1: # If a key is selected
print keys.GetValue() #print the key's value
We'll get it working eventually deepshade. :slightly_smiling_face: