Hmm, that's a bit of a tricky problem. If you knew what a given node would
be named after being pasted, you could just map that to the expected input,
but you can't really know that, since the pre-copy stack order is arbitrary.
There are two ways that come to mind to tackle this that are a good balance
of simplicity and reliability:
1) When PostageStamp nodes are copied, modify each one's 'label' knob before
storing it by appending a token string to it (something obscure that someone
else won't have put in there), followed by the name of the node that should
be connected to the pasted PostageStamp's input (you could conceivably add a
separate knob to each one instead, but the overhead would be much higher,
and using the 'label' field only requires a trivial amount of string
parsing).
Then, on paste, simply check each resulting PostageStamp node's label for
the token string and corresponding input name, hook things up based on what
you find, and strip that value from the label.
2) Don't do anything on copy, but when the nodes are pasted, inspect the
clipboard contents to find the names of the PostageStamp nodes that were
previously copied and store them in a list in the order found. After the
clipboard contents are pasted, the list of names should correspond to the
order of the PostageStamp nodes that were just pasted as they will appear in
nuke.selectedNodes(), but reversed.
Thus, you simply loop through nuke.selectedNodes(), and each time you
encounter a PostageStamp, grab the next name from your (now reversed) list
of names, and connect the pasted node to the named node's current input.
There's also an outside chance I'm overlooking something really obvious, as
I'm quite tired, but I hope this helps some.
-Nathan
-----Original Message-----
From: Adam Wierzchowski
Sent: Tuesday, June 04, 2013 10:51 PM
To: nuke-python@support.thefoundry.co.uk
Subject: [Nuke-python] Node order after nodeCopy and nodePaste
Hi,
thanks for your answer. I'm trying to modify poststampCopyPaste script:
http://cameroncarson.com/scripting/
Problem is it stores only single input. My idea was to replace postInput
with array where input of every PostageStamp is stored. Otherwise None
value is stored. If I had same node order after paste I could simply
check ith entry in postInput and if it is != None use it as input for
pasted PostageStamp.
regards
Adam
nuke.selectedNodes() will return the selected nodes in the order they
appear
on the node stack. In other words, the most recently selected or created
node will be at the top of the stack (and thus at the front of the
returned
list).
When you paste them, they are created in script order (imagine reading
through a Nuke script in a text editor and creating nodes as you encounter
their class names). Thus, the most recently created node (the "bottom"
node
in a simple tree) will end up at the top of the stack after pasting.
However, there is no way to predict the order in which a user selected a
collection of nodes. You could try to re-sort the selection into
topological
order using one or more simple graph algorithms, but without knowing the
exact method Nuke uses to decompose a DAG, it may be hard to cover all
cases.
If you can provide a little more information about what you're trying to
do,
it may help inform some solutions.
-Nathan
-----Original Message-----
From: Adam Wierzchowski
Sent: Tuesday, June 04, 2013 9:53 AM
To: Nuke Python discussion
Subject: [Nuke-python] Node order after nodeCopy and nodePaste
Hi,
I'm modifying default copy paste behaviour
for n in nuke.selectedNodes():
#store some params in global array
nuke.nodeCopy(nukescripts.cut_paste_file())
nuke.nodePaste(nukescripts.cut_paste_file())
for n in nuke.selectedNodes():
#restore some params from global array
Problem is that node order in first loop is different from order in
second. For example
Copy:
ColorBars1
PostageStamp1
Paste:
PostageStamp2
ColorBars2
Is there any pattern which could be used to correlate copied and pasted
nodes?
regards
Adam
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python