How can I get the dimensions of a newly-created material node via Python? I am using a Python startup script to add repetitious details to
a scene.  Arranging the nodes of the network for a new Cycles material
is cleaner if I know the size of each node as it is created.  The height
and width attributes are not correct, but the dimensions attribute
is accurate &mdash; once it is set up.

What I am looking for is a way to get the dimensions attribute
updated right after the node is created.  (My current workaround
uses a table of node sizes.)

If I run the equivalent of


    import bpy
    mats = bpy.data.materials
    mat = mats['GlossyGreenMaterial']
    nods = mat.node_tree.nodes
    newNode = nods.new('ShaderNodeBsdfGlossy')
    newNode.name = 'Glossy BSDF added'


to set up the node and then immediately execute


    print('newNode.dimensions: ', newNode.dimensions)


it will display


    newNode.dimensions:  &lt;Vector(0.0000, 0.0000)&gt;



If I bring up the Node Editor so the node is drawn and then
execute the print statement again it provides the expected


    newNode.dimensions:  &lt;Vector(150.0000, 142.0000)&gt;


Is there some update routine I could call as each node is
added that would cause the dimensions attribute to be set?


Thanks,
Roy Earle
There seems to be a solution to this (see below). Keep in mind, though, that while in general this approach is not recommended, in some cases it may work just fine.

Add this call to your script to force a re-draw, which will update the node’s dimensions properly.

bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)


Tip: if you add multiple nodes to the hierarchy (via your script) it may be smarter to add all nodes first then call this only once to minimize messing with blender’s drawing loop.

You can read more about this here:

https://docs.blender.org/api/2.79/info_gotcha.html?highlight=redraw#can-i-redraw-during-the-script

To be honest, I don’t understand exactly why blender doesn’t update the node’s dimensions right after it is added to the node hierarchy. It may be just an oversight, or perhaps blender really needs to re-draw everything once before it can figure out the dimensions.