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
$\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$
  • $\begingroup$ I would never have thought that this panel is called 'UI'. Thank. $\endgroup$ – Влад Киндюшов Mar 24 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.