Hi,
I spent some time yesterday trying to develop a Python script, which travels through takes, grabbing camera position (which is changed every time by aligning to spline tag), creating a null object and copying camera Matrix to null. The part I'm struggling with is grabbing the camera position. I either got the original camera position, before it's been modified by aligning to spline property or value 0.
Below is my code and also attached scene, which I've been using for tests.
Am I missing something obvious?
import c4d
from c4d import documents
list_of_takes = []
parent_name = "360_cams"
def GetCategory(doc):
takeData = doc.GetTakeData()
if takeData is None:
return
mainTake = takeData.GetMainTake()
take = mainTake.GetDown()
while take is not None:
list_of_takes.append((take))
take = take.GetNext()
def CreateParentObject4360CamExport(doc):
cam_export_parent = doc.SearchObject(parent_name)
if cam_export_parent is not None:
cam_export_parent.Remove()
c4d.CallCommand(5140) # Null
cam_export_parent = doc.SearchObject("Null");
c4d.CallCommand(1019940) # Reset PSR
if cam_export_parent != None:
cam_export_parent.SetName(parent_name)
return cam_export_parent
def CreateCopyOfTheCamera(currentCam,currentTake, doc,take_data):
c4d.CallCommand(5103) # Camera
camTemp = doc.SearchObject("Camera")
c4d.CallCommand(1019940) # Reset PSR
if camTemp != None:
camTemp.SetName(currentTake.GetName())
print("current cam : "+ currentCam.GetName() + " and position " + str(currentCam.GetMg()))
camTemp.SetMg(currentCam.GetMg())
c4d.EventAdd()
return camTemp
# Main function
def main():
doc = documents.GetActiveDocument()
takeData = doc.GetTakeData()
if takeData is None:
raise RuntimeError("No take data in the document.")
cam_export_parent = CreateParentObject4360CamExport(doc)
main_take = takeData.GetMainTake()
GetCategory(doc)
for child_take in list_of_takes:
takeLoaded = takeData.SetCurrentTake(child_take)
if takeLoaded == True:
currentCam = child_take.GetCamera(takeData)
cam2NullClone = CreateCopyOfTheCamera(currentCam,child_take,doc,takeData)
cam2NullClone.InsertUnder(cam_export_parent)
c4d.EventAdd()
# Execute main()
if __name__=='__main__':
c4d.CallCommand(13957) # Clear Console
main()