If that code was just to build a list, definitively use Nathan's way as I would write in the same manner. It is clean, simple, and efficient. If the loop is meant to do more than that, then you can use the default loop layout and add statements as needed.
Cheers. On Fri, Jan 4, 2013 at 4:24 PM, Rich Bobo <richb...@mac.com> wrote: > Nathan - Thanks! I also was thinking about doing an on-the-fly filtering > but, being a novice, I couldn't fathom the right syntax… > > I'll use your suggestion to make my code a bit shorter and keep Nico's > solution in my toolkit for another day! > > Rich > > > On Jan 4, 2013, at 7:17 PM, Nathan Rusch <nathan_ru...@hotmail.com> wrote: > > Looks like a reply to this showed up in nuke-python instead of > nuke-users, so this is a duplicate response. > > It’s much more efficient to simply filter the nodes as you assemble a list: > > notViewers = [n for n in nuke.selectedNodes() if n.Class() != 'Viewer'] > > -Nathan > > > *From:* Rich Bobo <richb...@mac.com> > *Sent:* Friday, January 04, 2013 4:12 PM > *To:* Nuke user discussion <nuke-users@support.thefoundry.co.uk> > *Subject:* Re: [Nuke-users] How to get all but one class in > nuke.selectedNodes…? > > Nico, > > Thanks for the speedy response! > > I only care about removing Viewers from the "selected collection" - I > don't care about what they are actually connected to. > > As I was thinking about the problem, it did occur to me that maybe I need > to treat the selected nodes as a list and use .remove, but I wasn't sure > how to go about it. And, I was unfamiliar with the shorthand for working on > a copy of the list! > > I'll give your code a try. ...If it works, I'm going home! ;^) > > Thanks, > > Rich > > > On Jan 4, 2013, at 6:56 PM, Nico Dufort <nduf...@gmail.com> wrote: > > Your code does nothing to remove anything from your collection. Did you > mean something similar to this: > > collection = nuke.selectedNodes() > for n in collection[:]: # use a copy of your list to be able to remove > items from it > if n.Class() == 'Viewer': > n['selected'].setValue(False) > collection.remove(n) > > At this point, your viewers are deselected and not part of your collection. > > That being said, you mentioned something about them being "connected", but > your code did not address anything with connection. Is this what you were > after, or you really needed something around the connection between nodes > and viewers to be dealt with? > > Cheers. nico > > On Fri, Jan 4, 2013 at 3:44 PM, Rich Bobo <richb...@mac.com> wrote: > >> Hi, >> >> I can't get my brain to figure this out, so I'm reaching out to the >> "collective brain"… 8^) >> >> I need a collection of nodes, minus any connected Viewers. So, selNodes = >> nuke.selectedNodes() --- but without any Viewers that may be connected... >> >> I can do this: >> >> selNodes = nuke.selectedNodes() >> for node in selNodes: >> if node.Class() == 'Viewer': >> node["selected"].setValue(False) >> else: >> node['selected'].setValue(True) >> >> However, that does not change the original collection of nodes - it >> still has all of the nodes that were connected when I set the origin >> variable, including any Viewers. I want to *remove* any Viewer class nodes >> from the selNodes collection! >> >> I know it's probably simple, but it's been a long week… Any help? >> >> Thanks! >> >> Rich >> >> >> Rich Bobo >> Senior VFX Compositor >> Armstrong-White >> http://armstrong-white.com/ >> >> Email: richb...@mac.com >> Mobile: (248) 840-2665 <%28248%29%20840-2665> >> Web: http://richbobo.com/ >> >> "Until one is committed, there is hesitancy, the chance to draw back >> ineffectiveness. Concerning all acts of initiative and creation, there is >> one elementary rule - the ignorance of which kills countless ideas and >> splendid plans; that the moment one definitely commits oneself, then >> Providence moves too. Things occur to help that would never otherwise have >> occurred. A whole stream of events issues from the choice, raising in one's >> favour all manner of unforeseen incidents and meetings and material >> assistance, which no man could have dreamed would have come his way." >> - Goethe >> >> >> >> >> >> >> >> >> >> >> >> >> _______________________________________________ >> Nuke-users mailing list >> Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ >> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users >> > > > > -- > "Attention, attention. Here and now, boys," the mynah repeated. "Here and > now, boys." > _______________________________________________ > Nuke-users mailing list > Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users > > > > Rich Bobo > Senior VFX Compositor > Armstrong-White > http://armstrong-white.com/ > > Email: richb...@mac.com > Mobile: (248) 840-2665 > Web: http://richbobo.com/ > > > "Few will have the greatness to bend history itself, but each one of us > can work to change a small portion of events, and in the total of all those > acts will be written the history of this generation." > - Robert F. Kennedy > > > > > > > ------------------------------ > _______________________________________________ > Nuke-users mailing list > Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users > _______________________________________________ > Nuke-users mailing list > Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users > > > > Rich Bobo > Senior VFX Compositor > Armstrong-White > http://armstrong-white.com/ > > Email: richb...@mac.com > Mobile: (248) 840-2665 > Web: http://richbobo.com/ > > "The nearest way to glory -- a shortcut, as it were -- is to strive to > be what you wish to be thought to be." > - Socrates, quoted in Cicero, 44 BC. > > > > > > > > > > > _______________________________________________ > Nuke-users mailing list > Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users > -- "Attention, attention. Here and now, boys," the mynah repeated. "Here and now, boys."
_______________________________________________ Nuke-users mailing list Nuke-users@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users