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.
Asked
Active
Viewed 3,657 times
8
-
Note that those API docs are for blender 2.69. See this question for the latest version. – gandalf3 Sep 15 '15 at 20:24
2 Answers
11
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.
gandalf3
- 157,169
- 58
- 601
- 1,133
-
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– batFINGER Jan 06 '19 at 08:00
