8
$\begingroup$

Is there a Python command that will allow me to set the camera clip end for viewing my objects in Blender (via scripting)? According to http://www.blender.org/api/blender_python_api_2_69_release/bpy.context.html the "bpy.context.space_data" variable is read-only.

$\endgroup$
1
  • $\begingroup$ Note that those API docs are for blender 2.69. See this question for the latest version. $\endgroup$
    – gandalf3
    Commented Sep 15, 2015 at 20:24

2 Answers 2

11
$\begingroup$

bpy.context.space_data is read-only, but it's properties are not.

For the active scene camera

context.scene.camera.data.clip_end

This gets the clip_end value for the active camera from the current scene, assuming there is one. If the current scene doesn't have an active camera, then context.scene.camera is None and this will raise an AttributeError.

For the viewport:

for a in bpy.context.screen.areas:
    if a.type == 'VIEW_3D':
        for s in a.spaces:
            if s.type == 'VIEW_3D':
                s.clip_end = <your value>

This iterates through all areas in the current screen until it finds a 3D view, then iterates through all spaces in the 3D view until it finds a 3D view space, which is the object containing the clip_end property.

$\endgroup$
1
  • $\begingroup$ This one came up as a link in new post. The camera object, and its data (from bpy.data.cameras) may not always have the same name, suggest using cam = context.scene.camera.data $\endgroup$
    – batFINGER
    Commented Jan 6, 2019 at 8:00
0
$\begingroup$

Here is an example of the same data for a driver.

enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .