The with statement is basically the same as doing:

def button_a():
    mygroup = nuke.toNode("Group1")
    try:
        mygroup.begin()
        nuke.nodes.Blur()
        some_func_which_errors_sometimes()
    finally:
        mygroup.end()

That is, always calling ".end()" even if an error occurs. I.e it "cleans up" after itself.

For example, say you have two unrelated menu commands - one makes a blur in a group, the other just makes a grade node (nothing at all to do with the group)

def button_a():
    mygroup = nuke.toNode("Group1")
    mygroup.begin()
    nuke.nodes.Blur()
    some_func_which_errors_sometimes()
    mygroup.end()

def button_b():
    nuke.nodes.Grade()

button_b() # makes Grade node in root, good
button_a() # makes Blur node in group, good, but then errors
button_b() # now makes Grade in group, bad

This happens because "mygroup.end()" never got called, whereas the "with" statement ensures this happens:

def button_a():
    mygroup = nuke.toNode("Group1")
    with mygroup:
        nuke.nodes.Blur()
        some_func_which_errors_sometimes()

On 23/11/16 04:27, Igor Majdandzic wrote:
Hows the with statement working here? I was always defining group.begin
and end. This looks much more elegant



Von Samsung Mobile gesendet



-------- Ursprüngliche Nachricht --------
Von: Ben Dickson <[email protected]>
Datum: 22.11.2016 3:44 (GMT+01:00)
An: Nuke user discussion <[email protected]>
Betreff: Re: [Nuke-users] create a node outside a grouped gimzo


"with nuke.thisParent():" would be the other way, which would also work
in the (uncommon) case of working inside nested group nodes

On 22/11/16 08:06, Gabor Hovanyi wrote:
 > with nuke.root():
 >      nuke.createNode('Reformat')
 >
 > => http://community.thefoundry.co.uk/discussion/topic.aspx?f=190&t=102206
 >
 > On Mon, Nov 21, 2016 at 1:24 PM, Darren Coombes <[email protected]
 > <mailto:[email protected]>> wrote:
 >
 >     I’ve got a grouped gizmo, and i want to create a reformat node.
 >     I’ve got it to create a reformat node, but it makes the node inside
 >     the group.
 >     Any idea how you’d get it to work so it creates it outside the group?
 >
 >     Thanks.
 >
 >     Check out some of my work...
 >     *
 >     *www.vimeo.com/darrencoombes/reel2015
 >     <http://www.vimeo.com/darrencoombes/reel2015>*
 >     *
 >     *
 >     *
 >     *
 >     *
 >     *
 >     *Mob: +61 418 631 079 <tel:+61%20418%20631%20079>*
 >     *
 >     IMDB: www.imdb.com/name/nm3719099/
<http://www.imdb.com/name/nm3719099/>
 >     *
 >     *Instagram: @7secondstoblack*
 >     *Instagram: @durwood0781*
 >     *Skype:  darren.coombes81*
 >     *Twitter:  @durwood81*
 >     *
 >
 >
 >     _______________________________________________
 >     Nuke-users mailing list
 >     [email protected]
 >     <mailto:[email protected]>,
 >     http://forums.thefoundry.co.uk/ <http://forums.thefoundry.co.uk/>
 >     http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
 >     <http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users>
 >
 >
 >
 >
 > _______________________________________________
 > Nuke-users mailing list
 > [email protected], http://forums.thefoundry.co.uk/
 > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
 >

--
ben dickson
2D TD | [email protected]
rising sun pictures | www.rsp.com.au
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users


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


--
ben dickson
2D TD | [email protected]
rising sun pictures | www.rsp.com.au
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users

Reply via email to