2

Using this post, I was able to change the clipping in the current workspace.

Setting camera clip end via Python

I would like all workspaces to have the same clipping. I came up with the following logic, which does not work properly.

min_clip = 1
max_clip = 500
for workspace in bpy.data.workspaces:
            bpy.context.window.workspace = workspace
            for area in bpy.context.screen.areas:
                if area.type == 'VIEW_3D':
                    for space in area.spaces:
                        if space.type == 'VIEW_3D':
                            space.clip_start = min_clip
                            space.clip_end = max_clip

It still only changes the clipping in the Scripting workspace.

Thanks alot

quest-12
  • 143
  • 4

1 Answers1

2

Don't change context to iterate over context, just iterate over the workspaces:

import bpy
from bpy import data as D

min_clip = 1 max_clip = 500 for workspace in D.workspaces: for screen in workspace.screens: for area in screen.areas: if area.type == 'VIEW_3D': for space in area.spaces: if space.type == 'VIEW_3D': space.clip_start = min_clip space.clip_end = max_clip

If you don't like stacking indentation:

import bpy
from bpy import data as D

min_clip = 1 max_clip = 500 screens = (s for w in D.workspaces for s in w.screens) V3Dareas = (a for s in screens for a in s.areas if a.type=='VIEW_3D') V3Dspaces = (s for a in V3Dareas for s in a.spaces if s.type=='VIEW_3D') for space in V3Dspaces: space.clip_start = min_clip space.clip_end = max_clip

Markus von Broady
  • 36,563
  • 3
  • 30
  • 99