Hi all,
I’m trying to make a little script that takes all selected cameras and puts them in a (newly created) stage object (one camera per frame).
Super useful if you want to render out stills on a render farm that doesn’t support takes.
I’ve got almost everything working:
- Getting the selected cameras and putting them in an array.
- Creating a stage object
- Looping through the array and putting the cameras into the camera slot of the stage object.
- Moving 1 frame forward
The two things I’m struggling with:
- How to key frame the camera slot properly so it actually creates the animation (different camera per frame). I’m using the mydoc.RecordKey() property but how do I find out which id (?) the camera property has?
- Ideally I want to catch errors when someone selects something other than a camera. Is there an easy way to catch that error? Should I loop through the array and check the individual elements?
Who can point me into the right direction?
Your help is much appreciated.
Best regards,
Martijn
script:
import c4d, math
from c4d import gui
# This is a little script that puts the selected cameras into a stage object with keyframes
# Main function
def main():
# Clear Console for easy debugging
c4d.CallCommand(13957, 13957)
# Get selected cameras
obj = doc.GetActiveObjects(1)
# Check if selected objects are cameras, if not pop-up error
#code should come here
# Go to Start of timeline
c4d.CallCommand(12501)
#create stage object
stage = c4d.BaseObject(c4d.Ostage)
doc.InsertObject(stage)
# Get active document
mydoc = c4d.documents.GetActiveDocument()
# Loop through the array of cameras & put selected cameras in stage object
for x in obj:
mytime = mydoc.GetTime()
myfps = mydoc.GetFps() # define prject fps
myframe = mytime.GetFrame(myfps) #get current frame
print(myframe) # print frame number
stage[c4d.STAGEOBJECT_CLINK] = x # put camera camera slot of stage object
#set keyframe How??
#mydoc.RecordKey(stage,[c4d.ID_BASEOBJECT_REL_ROTATION,c4d.VECTOR_X]) #Add the keyframe to Rotation X successfully
mydoc.RecordKey(stage, 1)
# Go to next key frame
c4d.CallCommand(12414)
c4d.EventAdd() #update
# Execute main()
if __name__=='__main__':
main()