Hi there,
I have a script that worked well in 3.0 but I just updated to Blender v3.5 and it no longer works now
The script split the area then switch to the modifier tab in the new property area created. The part of code that create the new area is working but the last 2 lines thatās supposed to switch the tab donāt work. If any code magician can fix it it will be awesome!
Define ādoesnāt workā. What happens when you run this? What errors do you see in the system console?
It just donāt do the tab switch, no error, Iām pretty sure itās the second to last line of code āthat donāt have the right area referenceā
From what I see, the scripts works great if it is run statement by statement from the user. However if it runs in one-go it will fail.
The problem is that once the new area is created from the split, Blender needs a little bit of time to get updated and let things settle, until you are able to access the bpy again.
You can break the execution into two parts, and to let the second part be executed through a scheduled thread (delayed-async execution).
import bpy
# global variables
# * because you can't get context inside thread functions
C = bpy.context
A = C.area
def split_area_function_2():
'''second function to change ui and space'''
print('changing context...')
# find the new created area
area = C.screen.areas[-1]
# try to change active context
area.ui_type = 'PROPERTIES'
area.spaces.active.context = 'MODIFIER'
def split_area_function():
'''first function to split the area'''
print('splitting area...')
# split area
w = (300 / A.width-1)*-1
bpy.ops.screen.area_split(direction='VERTICAL', factor=w)
# wait a little bit, then call the second function
bpy.app.timers.register(split_area_function_2, first_interval=1)
split_area_function()
Is this better to be done with despgraph
? Who knowsā¦
I was afraid of any api change but seems it is not the case, thanks for your example I will study it (Iām very not familiar with coding).
One thing strange is if I launch the script while the mouse is hover a property area it works. It split the area then switch the tab. Also It works from the script editorā¦
I donāt really know why but I managed to make it works again! I think it started to work when I split manually the main 3D view to have two 3D View then I closed the original and now bam it works again. And to keep things working for ever I saved the default startup file and now it works like before
I think it may be a long time bug because I do remember I also had to deal with something like this before with previous version 3.0. Itās like the default 3D View is not āregisterā or have something wrong in it that prevent the script to work properlyā¦ or maybe I found a hack with my small coding knowledge haha!
Perhaps it has to do with how you select the area C.screen.areas[-1]
, this means that you are sure that the area is on the last position.
I wonder though if this is not the case exactly, if you actually need to double check that you select the correct area.
Say for example you collect all areas in this array
areas = [area1, area2, area3]
and then once you create the new area it goes like this
newareas = [area1, newarea, area2, area3]
example:
a = [1,2,3]
b = [1,1500,2,3]
d = list(set(a) ^ set(b))
print(d)
This is just a random thought, if you are interested to try it.