# camera_to_view_selected() only selects a small section of the object in a script, works fine when I manually use the console

Here is the code I am using (in a python script):

for obj in bpy.context.scene.objects:
obj.select_set(False)

for obj in bpy.context.visible_objects:
if not (obj.hide_get()):
obj.select_set(True)

bpy.ops.view3d.camera_to_view_selected()

bpy.context.scene.render.filepath += "image"
bpy.ops.render.render(write_still=True)


Which produces this result:

But if I manually go into blender and paste the code in, I get this result (excuse the textures/colors being messed up, I was just too lazy to manually adjust everything):

Which is the result I was trying to get using the python script by itself. What am I doing wrong?

• How are you calling / using the Python script in your first case? It works fine when bpy is imported first. – Robert Gützkow Dec 3 '19 at 20:22
• Hello and welcome to the site! Could you please elaborate a bit and maybe explain what the script is supposed to do? And in what ways does the actual outcome differ from the expected one? That way one does not have to try and retrieve this information from the python script and images by themselves, but rather have the right idea of your question right away. – palkonimo Dec 3 '19 at 21:10