5
$\begingroup$

I'm trying to add some cameras to my scene that are orthographic. For this I am using:

add camera
bpy.ops.object.camera_add(view_align=False, enter_editmode=False, location=(-12, 12, 12), rotation=(0.0, 0.0, 0.0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, ))

 make the camera of type orthographic
bpy.data.cameras["camera.001"].type('ORTHO')

I want all the cameras to be Orthographic, but i don't know how. I cant get this to work. I know that it is an ENUM, but i dont know what to do with it.

How can I set these to be orthographic?

$\endgroup$
  • $\begingroup$ Python doesn't have enums. It's just a string. $\endgroup$ – Matt Mar 11 '14 at 19:39
  • 1
    $\begingroup$ Enums were added in python 3.4 legacy.python.org/dev/peps/pep-0435 $\endgroup$ – Tim Mar 11 '14 at 20:09
2
$\begingroup$

The values to set for the types are: 'PANO', 'PERSP' and 'ORTHO' in your case, you would loop over all objects and check whether they are cameras and assign 'ORTHO'

import bpy

for obj in bpy.context.scene.objects:
    if obj.type == 'CAMERA':
        print(obj.data.type)
        obj.data.type = 'ORTHO'
$\endgroup$
3
$\begingroup$

Orthographic can be set with:

bpy.data.cameras['Camera'].type = 'ORTHO'
$\endgroup$
  • $\begingroup$ Thanks! It works. It's a bit weird though that I have to set ORTHO with cam = bpy.data.cameras['Camera'] after having set location with cam = bpy.data.objects["Camera"]. Am I doing things wrongly? $\endgroup$ – Sibbs Gambling Nov 16 '16 at 23:43
  • $\begingroup$ @SibbsGambling Sorry, I don't know what you mean. Feel free to ask a new question if you have an issue. $\endgroup$ – Ray Mairlot Nov 17 '16 at 0:14
  • $\begingroup$ Oh just that bpy.data.cameras['Camera'] doesn't have a location attribute. To set that attribute, I need to do bpy.data.objects["Camera"]. I said it's weird because essentially it's the same thing, but I need to retrieve it differently for setting different attributes. $\endgroup$ – Sibbs Gambling Nov 17 '16 at 0:22
  • 1
    $\begingroup$ You would see the same thing for curves or armatures. When you're accessing bpy.data.cameras you're not accessing the camera object you're accessing the camera datablock which is then attached to the camera object. Similar issue here. If you need more information it's better to ask as a separate question as comments aren't for this kind of discussion. $\endgroup$ – Ray Mairlot Nov 17 '16 at 0:50
  • $\begingroup$ This is so very helpful! Thanks for the explanation! $\endgroup$ – Sibbs Gambling Nov 17 '16 at 1:48

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.