Worldcam shows from the bottom after bpy.ops.view3d.object_as_camera()

I set a camera active in a script by bpy.ops.view3d.object_as_camera(). This works fine. But when i press Numpad 0 to leave the camera view then the world camera shows from the bottom. Which doesn’t happen when i call the bpy.ops.view3d.object_as_camera() from the menu. Any ideas what is going on here?

A script to test the behaviour. The baddie resides at line 20.

import bpy

# ----------------------------------------- create isometric camera
class createtrueisocam(bpy.types.Operator):
    """Creates a mcamera for mathematical correct isometric view"""
    bl_idname = "scene.create_trueisocam"
    bl_label = "TrueIsocam"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        
        # ----------------------------Create Camera with correct position and rotation
        bpy.ops.object.camera_add(location=(30.60861, -30.60861, 30.60861)) 

        object = bpy.context.scene.objects.active
        object.rotation_euler = (0.955324, 0, 0.785398) #Attention, these are radians. Euler angles are (54.736,0,45)

        # ------------------------------Here we adjust some settings ---------------------------------
        object.data.type = 'ORTHO' # We want Iso, so set the type of the camera to orthographic
        
        
        bpy.ops.view3d.object_as_camera() # Set the current camera as the active one to look through

        return {'FINISHED'}

class MyPanel(bpy.types.Panel):
    bl_label = "Create IsoCam"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"

    def draw(self, context):
        self.layout.operator("scene.create_trueisocam")
# -------------------------------------------------------------------------------------------
    
def menu_func(self, context):
    self.layout.operator(createtrueisocam.bl_idname)
   

def register():
    bpy.utils.register_class(createtrueisocam)
    bpy.types.VIEW3D_MT_view.append(menu_func)
    bpy.utils.register_class(MyPanel)
    

def unregister():
    bpy.utils.unregister_class(createtrueisocam)
    bpy.types.VIEW3D_MT_view.remove(menu_func)
    bpy.utils.register_class(MyPanel)


if __name__ == "__main__":
    register()
            
            
            

Any thoughts and help is very welcome :slight_smile:

While at it, may i ask another newbee question? I can call bpy.ops.view3d.object_as_camera() in the above script without problem. But when i try to run the command alone then i get a warning in the console. Why does this one here not work?

import bpy
bpy.ops.view3d.object_as_camera()

Funny, the problem doesn’t occur if you entered and left scene camera before creating the iso cam. Best to report to bug tracker!

when i try to run the command alone then i get a warning in the console

Probably http://blender.stackexchange.com/q/6101/1363

So it’s really not me? Phew. Okay, then let’s submit it to the Bugtracker. Thanks for confirming CoDEmanX! And thanks for the link. That explains it. The mouse is at the text panel in the moment when i run the script :slight_smile: