VFXTalk.com Register | Blogs | Wiki | Facilities | RSS  
Home Forums The Pad News Gallery Reels Jobs Talent Members List Social Groups Search Today's Posts Mark Forums Read

Get your copy of Taskwise Today!
Use the form below to log on to your account. Dont have a account? Sign Up Now! its free and easy and you will be a part of the largest VFX Commnity on the Planet!


Go Back   VFXTalk.com > Visual Effects Packages > NUKE from The Foundry
Reload this Page python script problem

Reply
 
Thread Tools Display Modes
python script problem
Old
  (#1)
donat2 is Offline
Certified User
 
Posts: 49
Join Date: Apr 2007
   
python script problem - August 3rd, 2008, 03:27 PM

Hi,

I'm trying to write a simple python script and it doesn't work.

The goal of this script is to change the color of duplicate read nodes (so that I can delete those duplicates). That would allow me to drag and drop without worrying if I already have those read nodes, then run the script and delete the duplicate nodes.

Here's the script :

Code:
import nuke
for n in nuke.selectedNodes():
    if n.Class() == "Read":
        for m in nuke.allNodes():
            if n.knob("file") == m.knob("file"):
                n.knob("tile_color").setValue(0xe81414ff)
Nothing happens when I run this in the script editor. Can someone point me my mistake ?

Regards


Donat Van Bellinghen
www.nozon.com
  
Reply With Quote
VFXTalk Sponsored Links
Old
  (#2)
michaelmovies is Offline
Certified User
 
Posts: 221
Join Date: Sep 2004
   
August 4th, 2008, 11:47 AM

Well first off you're trying to check x.knob('file') without .value() at the end ... x.knob('file') returns the knob itself, not its value ... so your if statement is always False, as the two knobs are not in fact the same knob object.

Second you're going to find this fails because most nodes don't have a knob('file') and you'll get an error returned if any node in the selected group (allNodes) doesn't have a 'file' knob ... but in this case it's not reaching far enough to hit the error.

Try this:

Code:
import nuke
from random import randrange

# minCol and maxCol restrict color range
# 1 (full black) to 109951162776 (full white)
# stepCol defines how large of a step between iterations

minCol = 1
maxCol = 1099511627776
stepCol = 1024

selRead = [i for i in nuke.selectedNodes() if i.Class() == 'Read']
if len(selRead) != 0:
    for m in selRead:
        setCol = randrange(minCol, maxCol, stepCol)
        allReads = [i for i in nuke.allNodes() if i.Class() == 'Read']
        for i in allReads:
            if i.knob("file").value() == m.knob("file").value():
                i.knob("tile_color").setValue(setCol)
else:
    pass
  
Reply With Quote
Old
  (#3)
donat2 is Offline
Certified User
 
Posts: 49
Join Date: Apr 2007
   
August 6th, 2008, 01:30 PM

Thanks a lot Michael

I see that in your code you create two lists variables with list comprehension: selReads and allReads.

The allReads variable is created inside the first for loop. Is that mandatory ? Or could you define those two lists first, then proceed to the loop inside the loop ?

(Sorry if this is off-topic, I realize it's purely a Python problem unrelated to Nuke. I googled things like "nested loop scope python" but didn't find an answer)

Regards


Donat Van Bellinghen
www.nozon.com
  
Reply With Quote
Old
  (#4)
michaelmovies is Offline
Certified User
 
Posts: 221
Join Date: Sep 2004
   
August 6th, 2008, 01:40 PM

Quote:
Originally Posted by donat2 View Post
Thanks a lot Michael

I see that in your code you create two lists variables with list comprehension: selReads and allReads.

The allReads variable is created inside the first for loop. Is that mandatory ? Or could you define those two lists first, then proceed to the loop inside the loop ?

(Sorry if this is off-topic, I realize it's purely a Python problem unrelated to Nuke. I googled things like "nested loop scope python" but didn't find an answer)

Regards
Hey no problem ... vfx is as much about python these days as python is about vfx.

Nope, it's totally not mandatory ... in fact the only reason it's there is cause I was originally doing a variant where I was going to not change the color of the selected read, just the duplicates ... and well it all gets a bit complicated, but I really just wanted to answer the question in the shortest amount of time.

Actually to be most efficient in this case, allReads should be initialized immediately after the if len(selRead) != 0 statement. That way if selRead fails (there are no reads to check) you never bother wasting processor cycles on allReads, but it avoids the multiple duplications I've accidentally forced it to do in this case. List comps are very fast, but it's still not worth duping the work ... if I'd kept going down my original path I'd have needed to, but with the code I ended up with it's redundant.

Good catch.

Michael
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
python procedure in maya knish Maya 5 July 18th, 2008 09:48 PM
python ui script invoidzero NUKE from The Foundry 1 July 15th, 2008 03:35 PM
Python usage in Nuke worc NUKE from The Foundry 4 June 15th, 2008 01:26 AM


Get yo
ur copy Today!

Copyright © VFXTalk.com, 2009