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.
2 Answers
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.
-
$\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 usingcam = context.scene.camera.data
$\endgroup$ Commented Jan 6, 2019 at 8:00