Yep, you're right there - "finally" will always be called no matter what so if there's things that must be done that's the right place for them, while "except" would be where you stash the 'oh no, it broke?' code :D
Hi Anthony, Thank you so much for all your awesome tutorials.I am new to python and I have been learning a lot from your channel. I have a question about the multiple group nodes workaround. I have few group nodes and in each group node I have a read node inside of it. I would like to make a python button to reload all read nodes inside of all Group nodes. So far I made this script and it is working but it is working only on the last group node got selected. I knew it has to be some loop thing but when it comes to inside of group node, it gets difficult. I cannot figure it out the way to make this work with all group nodes. Could you give me some advice on this? Thanks! for a in nuke.allNodes(): if a.Class()=='Group': a['selected'].setValue(True)
s = nuke.selectedNode() with s: for a in nuke.allNodes(): if a.knob('reload'): a['reload'].execute()
Thanks! and aaah, yes, you're pretty close, however let me rewrite what you've got in pseduocode: ``` for a in all the nodes: if it's a group? select it s = the selected node (which will be the *last* node you selected..) with s: look at all the nodes inside the group press every reload button you can find ``` So your first section will select everything, but the *second* section will only run once. You can see there's a loop there, but it's looping through every node inside the group, rather than looping through every group node - you need a loop inside a loop in this case. Taking what you've got, the first section is where you're deciding what you want to work on (so in this case, all groups - you could easily change it to "all groups that are selected" or "all groups that have the word 'Magic' in them" etc). I've kept the same variable names so you can hopefully see how this maps to what you have ``` # decide what to work on all_the_groups = [] for a in nuke.allNodes(): # suggestion - check the help on allNodes, you can skip the this step :D if a.Class()=='Group': all_the_groups.append(a) # do something with the things we want to work on for s in all_the_groups: with s: for a in nuke.allNodes(): # this is the thing we want to do if a.knob('reload'): a['reload'].execute() ``` The selection thing is more for you being able to target something other than "everything" if that makes sense? (if not, I can handwave more)
@@tanantish ohhh I see what I did wrong! I knew it is something super small but I could not figure it out. Thank you so much! you are awesome. Btw I liked your video so I showed your channel to my friend who also works in this industry and he told me that he actually knew you in person. You worked the studio where my friend works at one point. Anyway Thank you so much and looking forward to watching your next video!
12:00 I think it s better to use "finally" instead of "except"
you want to exit the group no matter if there s error
Yep, you're right there - "finally" will always be called no matter what so if there's things that must be done that's the right place for them, while "except" would be where you stash the 'oh no, it broke?' code :D
Hi Anthony, Thank you so much for all your awesome tutorials.I am new to python and I have been learning a lot from your channel. I have a question about the multiple group nodes workaround. I have few group nodes and in each group node I have a read node inside of it. I would like to make a python button to reload all read nodes inside of all Group nodes. So far I made this script and it is working but it is working only on the last group node got selected. I knew it has to be some loop thing but when it comes to inside of group node, it gets difficult. I cannot figure it out the way to make this work with all group nodes. Could you give me some advice on this?
Thanks!
for a in nuke.allNodes():
if a.Class()=='Group':
a['selected'].setValue(True)
s = nuke.selectedNode()
with s:
for a in nuke.allNodes():
if a.knob('reload'):
a['reload'].execute()
Thanks! and aaah, yes, you're pretty close, however let me rewrite what you've got in pseduocode:
```
for a in all the nodes:
if it's a group? select it
s = the selected node (which will be the *last* node you selected..)
with s:
look at all the nodes inside the group
press every reload button you can find
```
So your first section will select everything, but the *second* section will only run once. You can see there's a loop there, but it's looping through every node inside the group, rather than looping through every group node - you need a loop inside a loop in this case.
Taking what you've got, the first section is where you're deciding what you want to work on (so in this case, all groups - you could easily change it to "all groups that are selected" or "all groups that have the word 'Magic' in them" etc). I've kept the same variable names so you can hopefully see how this maps to what you have
```
# decide what to work on
all_the_groups = []
for a in nuke.allNodes(): # suggestion - check the help on allNodes, you can skip the this step :D
if a.Class()=='Group':
all_the_groups.append(a)
# do something with the things we want to work on
for s in all_the_groups:
with s:
for a in nuke.allNodes(): # this is the thing we want to do
if a.knob('reload'):
a['reload'].execute()
```
The selection thing is more for you being able to target something other than "everything" if that makes sense? (if not, I can handwave more)
@@tanantish ohhh I see what I did wrong! I knew it is something super small but I could not figure it out. Thank you so much! you are awesome. Btw I liked your video so I showed your channel to my friend who also works in this industry and he told me that he actually knew you in person. You worked the studio where my friend works at one point. Anyway Thank you so much and looking forward to watching your next video!
Keep on doing! loved it