I want to use python to set the camera viewpoint but failed to do so, here is my code to render the model through python
import sys import os import bpy import math import datetime if __name__=="__main__": configureBlender() setCameraPosition([0.49123,-2.22974,6.74501],[123.942,0.578,0.1]) run(os.path.dirname(os.path.realpath(__file__))+'/test') def configureBlender(): # rendering constants RENDER_RES_X = 640 RENDER_RES_Y = 480 FRAME_NO = 1 bpy.context.scene.frame_current = FRAME_NO bpy.context.scene.render.resolution_x = RENDER_RES_X bpy.context.scene.render.resolution_y = RENDER_RES_Y bpy.context.scene.render.use_border = False def run(output_dir): bpy.context.scene.render.filepath = output_dir nodes = bpy.context.scene.node_tree.nodes links = bpy.context.scene.node_tree.links nodes['File Output'].base_path = output_dir bpy.ops.render.render(write_still=True) def setCameraPosition(location, rotation): bpy.data.objects['Camera'].location = location bpy.data.objects['Camera'].rotation_euler = [math.radians(rotation), math.radians(rotation), math.radians(rotation) ]
I don't know what is wrong with code or maybe model(anywhere to upload the model, it is 5mb)
for obj in bpy.data.objects: print(obj.name)
it prints out only one Camera object, i guess if there is only one camera, this camera must be the active camera.
Another wield thing is i changed the camera position and saved the model but it is still rendering with the previous viewpoint. so I guess maybe the code is fine but something wrong with the model.
here is my model link