On 04/04/2017 at 12:31, xxxxxxxx wrote:
Oh wow :dizzy_face: What an incredibly detailed answers! Huge!
Basically the concept you describe is exactly the same as the one I had, but something does not work yet.
gr4ph0s, it could be much easier, but as I have to deal with individual keys it all gets much more complicated. I decided that getting initial values without matrices is more straight-forward but it looks basically the same as in the variant you've described, on principal level.
I have red the article about Matrix before but thanks anyway, it seems I got it ))
ScottA, wow! Thank you for that huge piece of work)
I have written about the same thing, but I call tracks not in loop but strictly by their names because I noticed in Cinema you can add second or even third curve on the same property, so there may be a few curves you will get this way as I got it (still I completely can't understand what it could be used for and how to utilize it)
Anyway, that's my code
This is partially working snippet, still unfinished. It works but has a very strange problem. I see the content of staticRotation_parent is not corresponding to the curves_rotation. Both must contain X, Y and Z in that exact order, but in staticRotation_parent the order is strangly different as I discovered (not sure though, maybe the curves_rotation is wrong, but there's much less chances it is).
import c4d
from c4d import gui
import math
#Welcome to the world of Python
obj = doc.GetActiveObject()
inicialMg = obj.GetMg()
#GET TRACKS
tracks_position = [
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))),
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))),
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0)))
]
tracks_scale = [
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))),
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))),
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_SCALE, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0)))
]
tracks_rotation = [
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0))),
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Y, c4d.DTYPE_REAL, 0))),
obj.FindCTrack(c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_ROTATION, c4d.DTYPE_VECTOR, 0), c4d.DescLevel(c4d.VECTOR_Z, c4d.DTYPE_REAL, 0)))
]
#RETRIVE CURVES
curves_position = []
curves_scale = []
curves_rotation = []
for i in tracks_position:
if i:
curves_position.append(i.GetCurve())
else:
curves_position.append(None)
for i in tracks_scale:
if i:
curves_scale.append(i.GetCurve())
else:
curves_scale.append(None)
for i in tracks_rotation:
if i:
curves_rotation.append(i.GetCurve())
else:
curves_rotation.append(None)
#GET ABS VALS
parentObj = obj.GetUp()
if parentObj:
staticPosition_parent = parentObj.GetAbsPos()
staticScale_parent = parentObj.GetAbsScale()
staticRotation_parent = parentObj.GetAbsRot()
nParent = parentObj.GetUp()
#UNDO
doc.StartUndo()
#MOVE TARGET OBJECT FROM PARENT
if (nParent) :
doc.AddUndo(c4d.UNDOTYPE_DELETE, obj)
obj.Remove()
doc.AddUndo(c4d.UNDOTYPE_NEW, obj)
obj.InsertUnder(nParent)
else:
doc.AddUndo(c4d.UNDOTYPE_DELETE, obj)
obj.Remove()
doc.AddUndo(c4d.UNDOTYPE_NEW, obj)
doc.InsertObject(obj)
#UNDO
doc.EndUndo()
c4d.EventAdd()
#RESET GLOBAL MATRIX
obj.SetMg(inicialMg)
#COMPENSATE KEY VALUES
q = 0
for i in curves_rotation: #ITERATE CURVES ARRAY
if i: #ITERATE KEYS OF CURVE
q2 = 0
for l in range(i.GetKeyCount()) :
key = i.GetKey(q2)
value = key.GetValue() + staticRotation_parent[q]
key.SetValue(i, value)
q2 += 1
q += 1
# q = 0
# for i in curves_position: #ITERATE CURVES ARRAY
# if i: #ITERATE KEYS OF CURVE
# q2 = 0
# for l in range(i.GetKeyCount()) :
# key = i.GetKey(q2)
# key.SetValue(i, keysModified_position[q][q2])
# print(key.GetValue())
# q2 += 1
# q += 1
c4d.EventAdd()