2
$\begingroup$

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

$\endgroup$

1 Answer 1

2
$\begingroup$

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
$\endgroup$
2
  • $\begingroup$ I think nested for / ifs are way easier to read than double for comprehensions :) $\endgroup$
    – Gorgious
    Jun 8, 2022 at 9:17
  • $\begingroup$ @Gorgious those generator expressions fit my standards of readability, though barely... :) $\endgroup$ Jun 8, 2022 at 9:27

You must log in to answer this question.

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