The issue is that, in the context of your script block, the node’s screenWidth 
and screenHeight attributes are never updated when it is created using 
nuke.nodes.ColorCorrect(), so both methods return 0. If you use call .xpos() or 
.ypos() on the node before checking screenWidth() or screenHeight(), or create 
the node using nuke.createNode(), those attributes will be updated properly.

This seems like a bug/undesired behavior, so I think I’ll file something with 
support.

-Nathan



From: drossxyu 
Sent: Wednesday, July 18, 2012 1:49 PM
To: [email protected] 
Subject: [Nuke-python] Inconsistent script results

I'm trying to create a function that will snap one node to another node 
regardless of shape or size. Normally, If I try to match the position of, for 
example, a color correct node to a dot, it will not match based on the center 
of the node, but on the upper left hand corner of their bounding box. I found 
this to be annoying when trying to script the position of nodes on a grid, so I 
created this function.

The issue i'm running into is that it only works in one direction. If I try to 
snap a selected node to new color correct node, it works fine. If I try to do 
the opposite (color correct node to selected), it doesn't snap properly.

I have a feeling it has something to do with using the nuke.selectedNodes()[0] 
as it seems to work just fine if I create two new nodes from scratch and snap 
them in either direction.

      Code:  
      #snaps a node to a target node regardless of shape/size (i.e, dots, reads 
with stamps, regular nodes, etc.)

      def snap(sNode,target):

          #converts passed arguments to nodes if they aren't already

          if not isinstance(sNode,nuke.Node):
              sNode = nuke.toNode(sNode)

          if not isinstance(target,nuke.Node):
              target = nuke.toNode(target)

         #snaps your node to the target node 

          sNode.setXpos(target.xpos() + (target.screenWidth() / 2) - 
(sNode.screenWidth() / 2))
          sNode.setYpos(target.ypos() + (target.screenHeight() / 2) - 
(sNode.screenHeight() / 2))

      #---------------------------------------------------------------------

      #snaps selected node to new color correct node (works)

      #select a node first
      selected = nuke.selectedNodes()[0]
      myColorCorrect = nuke.nodes.ColorCorrect()
      snap(selected,myColorCorrect)

      #---------------------------------------------------------------------

      #snaps new color correct node to selected node (does not work)

      #select a node first
      selected = nuke.selectedNodes()[0]
      myColorCorrect = nuke.nodes.ColorCorrect()
      snap(myColorCorrect,selected)
     



--------------------------------------------------------------------------------
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to