bpy.ops.view3d.viewnumpad(type='CAMERA') from script.

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
poepping
Posts: 0
Joined: Mon May 16, 2011 2:39 am

bpy.ops.view3d.viewnumpad(type='CAMERA') from script.

Post by poepping »

I want to be able to trigger camera changes from a script (I'm trying to interface osc events to control blender functionality) I get the osc events fine, but when I try to change the view type to CAMERA sing the byp.ops.view3d.viewnumpad(type='CAMERA') I get:

expected a view3d region

Which from googling around means I need to be IN a 3dview when i run the command (which I assume would happen if this was registered as a menu?)

I've tried clicking in a 3dview port and then activating the script remotely, but it still seems to be running in the wrong context.

Anyone know how to get my script into the correct 3dview context? (maybe a select next 3d view function? :) )

thanks,
matt

nirenyang
Posts: 0
Joined: Wed Mar 16, 2011 10:21 am

Post by nirenyang »

I get the similar error:


>>>bpy.ops.view3d.snap_selected_to_grid()
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "D:\PROGRA~1\BLENDE~1\BLENDE~1\2.57\scripts\modules\bpy\ops.py", line 179, in __call__
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.view3d.snap_selected_to_grid.poll() expected a view3d region

SL1200
Posts: 0
Joined: Tue Jun 14, 2011 5:36 pm
Location: England

Re: bpy.ops.view3d.viewnumpad(type='CAMERA') from script.

Post by SL1200 »

Hi there, I'm very new to python so this may or may not help, I hope it does :)

bpy.context.area.type = 'VIEW_3D'


[/code]
Everyone I meet is my superior, and being that, they can teach me something new.

inx
Posts: 0
Joined: Tue Jun 14, 2011 2:08 pm

Post by inx »

just found this:

http://blenderartists.org/forum/showthr ... viewnumpad


to set all VIEW_3Ds to 'CAMERA' just iter through the areas:

Code: Select all

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        area.spaces[0].region_3d.view_perspective = 'CAMERA'

Post Reply