0
$\begingroup$

I have 1000+ cameras and I want to unwrap my mesh UV using project from view from all of them (so creating a UV layer from each camera's project from view) so I can add a UV_PROJECT modifier for each one to texture my mesh. However, Blender's project from view uses the current 3d view as its source. Therefore, I want to align my viewport to a selected camera before performing the project from view using Python.

How can I do this? On Blender's Aligning page, it provides "Align Active Camera to View" but not the inverse I need. I am new to Blender's API and workflow.

$\endgroup$
2
  • $\begingroup$ Have you tried bpy.ops.view3d.view_camera()? $\endgroup$
    – Psyonic
    Jun 19 at 7:48
  • $\begingroup$ It worked! Right now, the background image does not match up with the UV unwrap perfectly (scaling is off) but I am pretty sure it is because I am not projecting with bounds. @Psyonic if you want you can submit an answer so I can confirm it. $\endgroup$ Jun 19 at 21:45
0
$\begingroup$

This will iterate through all objects in your .blend If the object is of type CAMERA it gets set as the active scene camera, then the viewport is set to look through it

for ob in bpy.data.objects:
    if ob.type == 'CAMERA':
        bpy.context.scene.camera = ob
        bpy.ops.view3d.view_camera()
        # - YOUR CODE HERE -
$\endgroup$
1
  • $\begingroup$ Thank you! The code is helpful. $\endgroup$ Jun 20 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.