2020.5.7 python node.state

A question on the node.state behavior. Looks like the node.state is not available after the node is created pythonicaly?

import fx
n1 = Node(“com.digitalfilmtools.ofx.silhouette.sfx_copy”)
activeSession().addNode(n1)
print(n1.state)

the result is a empty list: {}
then if I run another script after this node was created and try to get the node state its working, like:
{‘graph.pos’: Point3D(-118.165,-67.061), etc…}

Is there a way to force the node to update/generate the state information on the same script run or is it a bug/intentional design?

The node state is there, it’s just empty when you first create it. You may need to deactivate/reactivate the session to get the Trees view to notice and lay out the new node, which will then set its initial position.
But if you don’t care about the node position, go ahead and set whatever state you want when you create it. It’ll be preserved.

Thanks, yeah I’m looking for the fresh node position after creation. Can you give me an example of Session deactivation? I’m not finding a specific method to desactivate or even update Tree.

Ive been trying a few things here but still the fresh node state wont update with the position info. For example I tried to activate another session in the project and activate the session that I created the node again and it wont update.

n1 = Node(“com.digitalfilmtools.ofx.silhouette.sfx_copy”)
p = activeProject()
activeSession().addNode(n1)
fx.activate(p.sessions[1]) # the other project session
fx.activate(p.sessions[0]) # the session that was active on node creation
print(n1.state)

Hmm - there may be a bug concerning when the tree will auto-layout.

Question - can you query the position of an existing node and set the position yourself, say by increasing the y coordinate by 40?

Sorry for the delay on the reply. I can query the position state of an existing node and set a new position, BUT the position will only update on the “tree view” if I drag the node with the mouse (it instantly goes to the new position visually), so yeah there’s something funky on the “tree view” update.

Yep - probably the same issue. I didn’t design the tree to notice those kinds of changes via scripting. We can get that fixed in an update.

Magno - the Trees window will notice the new node position if you set the position inside an undo block. In fact, if you want the UI to notice any changes to the object model (such as adding the new node, or adding pipes to it), you’ll need to do it inside an undo block.

You can still make changes like this outside of an undo block, but you should only do that when you are manipulating the model during some kind of render script or something outside of the UI environment.

That said, I did fix the issue with the Trees window not immediately noticing the new node when it is first added, using it’s default position in the tree (0, 0).

Yes, :heart: creating nodes inside the undo is doing the trick. Thanks!!!