Hello,
I'm trying to set keyframes for any type of UserData that can be set with a float value (Value CTracks). I believe those are Real, Long, Vector, Vector 4D, Color, & Matrix. Using this article from Cineversity as my guide, I've hit three issues and could use some help.
-
Setting the Min & Max values for Vectors
I want to get the min & max values for a CTrack so if I try to set the value to something out of range, it defaults to either the minimum or maximum value. I am confused how to go about this. -
Keyframing the 'x', 'y', & 'z' of the User Data's Matrix Vectors
Currently I'm just setting keyframes on the Matrix Vectors themselves, not their 'x', 'y', & 'z' values. I can tell because the CTracks do not belong to the object and when I keyframe manually, they do.
This is how it should look (this was done with manual keyframing):
-
Getting 'w' CTrack in Vector 4D Data Type
When keyframed manually, Vector 4D shows a CTrack for 'w' but there doesn't seem to be aVECTOR_W
.
This is with manual keyframing:
My results (from the code below) do not target the Matrix's x, y, z and neither those tracks nor the Vector 4D are not being added to the Circle's User Data group:
Here is my code and a scene file with an object that has many userdata types:
import c4d
def GetUDCtracks(op,id):
cTracks = []
ud = id[1]
dtype = ud.dtype
if dtype in (c4d.DTYPE_VECTOR,c4d.DTYPE_COLOR):
for v in xrange(c4d.VECTOR_X, c4d.VECTOR_Z+1):
descID = c4d.DescID(id[0],id[1],c4d.DescLevel(v,c4d.DTYPE_REAL))
cTracks.append(c4d.CTrack(op,descID))
elif dtype == c4d.DTYPE_VECTOR4D:
for v in xrange(c4d.VECTOR_X, c4d.VECTOR_Z+2): # How to get Vector4D.w?
# this is not adding under the correct user data group
descID = c4d.DescID(id[0],id[1],c4d.DescLevel(v,c4d.DTYPE_REAL))
cTracks.append(c4d.CTrack(op,descID))
elif dtype == c4d.DTYPE_MATRIX:
# This is not adding the correct cTrack (x,y, or z) to the cTracks list
# nor is it adding under the correct user data group
for v in xrange(c4d.MATRIX_OFF, c4d.MATRIX_V3+1):
descID = c4d.DescID(id[0],id[1],c4d.DescLevel(v,c4d.DTYPE_LONG))
for i in xrange(c4d.VECTOR_X, c4d.VECTOR_Z+2):
descID2 = c4d.DescID(descID[0],descID[1],c4d.DescLevel(i,c4d.DTYPE_REAL))
cTracks.append(c4d.CTrack(op,descID2))
else:
cTracks.append(c4d.CTrack(op,id))
return cTracks
def main(doc):
doc.StartUndo()
value = 1.0
keyTime = doc.GetTime()
for id, bc in op.GetUserDataContainer():
dtype = id[1].dtype
print "dtype: %s"%dtype
print "bc[c4d.DESC_NAME]: %s"%bc[c4d.DESC_NAME]
if dtype not in (c4d.DTYPE_MATRIX,c4d.DTYPE_REAL,c4d.DTYPE_VECTOR,
c4d.DTYPE_VECTOR4D, c4d.DTYPE_LONG, c4d.DTYPE_COLOR):
continue
print "bc[c4d.DESC_MAX]: %s"%bc[c4d.DESC_MAX]
print "bc[c4d.DESC_MIN]: %s"%bc[c4d.DESC_MIN]
cTrack = op.FindCTrack(id)
if not cTrack:
cTracks = GetUDCtracks(op,id)
for track in cTracks:
print track
doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
op.InsertTrackSorted(track)
curve = track.GetCurve()
keyDict = curve.AddKey(keyTime)
myKey = keyDict["key"]
track.FillKey(doc,op,myKey)
doc.AddUndo(c4d.UNDOTYPE_CHANGE, op)
# How can I check the curve's min & max before setting the value
# if it's one dimension of a Vector?
myKey.SetValue(curve,value)
c4d.EventAdd(c4d.EVENT_ANIMATE)
doc.EndUndo()
if __name__=='__main__':
main(doc)
Any help with this would be tremendous! Thank you :trophy: