0
$\begingroup$

How do I get the width of the N Properties Panel in the 3D View using the Python API of Blender 2.8?

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

Area.width

The screen is made up of areas, each area has an x, y, width, height attribute.

Python console test code:

>>> for a in C.screen.areas:
...     a.type, a.width
...     
('PROPERTIES', 346)
('CONSOLE', 931)
('VIEW_3D', 346)
('TEXT_EDITOR', 931)

Region.width

within each area there are regions. Commonly there are 'HEADER', 'UI', 'TOOLS' and 'WINDOW' regions. For the 'VIEW_3D' region the N panel is region type 'UI'

>>> for a in C.screen.areas:
...     if a.type == 'VIEW_3D':
...         break
...         
>>> a.type
'VIEW_3D'

>>> for r in a.regions:
...     r.type, r.width
...     
('HEADER', 931)
('TOOLS', 1)
('UI', 335)
('WINDOW', 931)

If you are writing UI code to go in the N panel then can get the width directly with

context.region.width

Related:

Is there a way to determine the left 3D view sidebar's current width with python?

$\endgroup$
1
  • $\begingroup$ I would never have thought that this panel is called 'UI'. Thank. $\endgroup$ Commented Mar 24, 2019 at 13:53

You must log in to answer this question.

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