
| While waiting to be added to the Foundry forums - python/nu... | |||
|
Posted by: Daniel Ott ![]() Date: 04-27-2012, 12:30:PM |
lambda just returns an unnamed function... 'nuke.createNode(g)' would be the body of the function. 'g' won't get evaluated until you call the function, at which point you've already iterated through the list of gizmo's and g is left set to the last item in the list. One approach would be to just generate a string to be evaluated later on... nuke.menu( 'Nodes' ).addCommand( 'Gizmos/' + os.path.splitext(g)[0], "nuke.createNode('g')" % g ) Daniel Ott Ian Haskin wrote: > I'm new to Python and I'm coming to it from PHP. Can anyone shed light > on why the following snippit from my menu.py doesn't work to add custom > entries to the menu in Nuke? > > > > gizmoDir = 'Q:/Nuke_Extras/Plugins/Gizmos' > > gizmoList = os.listdir( gizmoDir ) > > for g in gizmoList: > > nuke.menu( 'Nodes' ).addCommand( 'Gizmos/' + os.path.splitext(g)[0], > lambda: nuke.createNode(g) ) > > > > > > I get proper menu names for each gizmo from " 'Gizmos/' + > os.path.splitext(g)[0] ", but "nuke.createNode(g)" always inserts the > last gizmo from "gizmoList"... So I get a menu group that launches the > same gizmo from multiple menu entries. > > > > I realize that this is a pretty basic thing to hit the list with, but I > haven't had any luck finding a solution online for what (I'm assuming) > is a simple error on my part. > > > > > > *Ian Haskin*** > > * *Sys-Admin, TOPIX > > ian@topixfx.com** > > 416-971-7711 x480 > > Description: topix_pong_email > > * www.topixfx.com * > > > > > ------------------------------------------------------------------------ > > To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscribe To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscribe |
||
| Re: While waiting to be added to the Foundry forums - pytho... | |||
|
Posted by: Ian Haskin ![]() Date: 04-27-2012, 13:15:PM |
Ok, that makes sense, however your example doesn't seem to work: TypeError: not all arguments converted during string formatting I'll keep playing with it... thanks for clarifying why the same gizmo was always loading in my example -----Original Message----- From: studiosysadmins-discuss-bounces@studiosysadmins.com [mailto:studiosysadmins-discuss-bounces@studiosysadmins.com] On Behalf Of Ott, Daniel Sent: Friday, April 27, 2012 12:26 PM To: discuss@studiosysadmins.com Subject: Re: [SSA-Discuss] While waiting to be added to the Foundry forums - python/nuke question lambda just returns an unnamed function... 'nuke.createNode(g)' would be the body of the function. 'g' won't get evaluated until you call the function, at which point you've already iterated through the list of gizmo's and g is left set to the last item in the list. One approach would be to just generate a string to be evaluated later on... nuke.menu( 'Nodes' ).addCommand( 'Gizmos/' + os.path.splitext(g)[0], "nuke.createNode('g')" % g ) Daniel Ott Ian Haskin wrote: > I'm new to Python and I'm coming to it from PHP. Can anyone shed > light on why the following snippit from my menu.py doesn't work to add > custom entries to the menu in Nuke? > > > > gizmoDir = 'Q:/Nuke_Extras/Plugins/Gizmos' > > gizmoList = os.listdir( gizmoDir ) > > for g in gizmoList: > > nuke.menu( 'Nodes' ).addCommand( 'Gizmos/' + > os.path.splitext(g)[0], > lambda: nuke.createNode(g) ) > > > > > > I get proper menu names for each gizmo from " 'Gizmos/' + > os.path.splitext(g)[0] ", but "nuke.createNode(g)" always inserts the > last gizmo from "gizmoList"... So I get a menu group that launches > the same gizmo from multiple menu entries. > > > > I realize that this is a pretty basic thing to hit the list with, but > I haven't had any luck finding a solution online for what (I'm > assuming) is a simple error on my part. > > > > > > *Ian Haskin*** > > * *Sys-Admin, TOPIX > > ian@topixfx.com** > > 416-971-7711 x480 > > Description: topix_pong_email > > * www.topixfx.com * > > > > > ---------------------------------------------------------------------- > -- > > To unsubscribe from the list send a blank e-mail to > mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=uns > ubscribe To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscri be To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscribe |
||
| Re: While waiting to be added to the Foundry forums - pytho... | |||
|
Posted by: Daniel Ott ![]() Date: 04-27-2012, 13:20:PM |
oops yeah change "nuke.createNode('g')" % g to "nuke.createNode('%s')" % g Ian Haskin wrote: > Ok, that makes sense, however your example doesn't seem to work: TypeError: > not all arguments converted during string formatting > > I'll keep playing with it... thanks for clarifying why the same gizmo was > always loading in my example > > -----Original Message----- > From: studiosysadmins-discuss-bounces@studiosysadmins.com > [mailto:studiosysadmins-discuss-bounces@studiosysadmins.com] On Behalf Of > Ott, Daniel > Sent: Friday, April 27, 2012 12:26 PM > To: discuss@studiosysadmins.com > Subject: Re: [SSA-Discuss] While waiting to be added to the Foundry forums - > python/nuke question > > lambda just returns an unnamed function... 'nuke.createNode(g)' would be the > body of the function. 'g' won't get evaluated until you call the function, > at which point you've already iterated through the list of gizmo's and g is > left set to the last item in the list. > > One approach would be to just generate a string to be evaluated later on... > > nuke.menu( 'Nodes' ).addCommand( > 'Gizmos/' + os.path.splitext(g)[0], "nuke.createNode('g')" % g > ) > > > Daniel Ott > > > Ian Haskin wrote: >> I'm new to Python and I'm coming to it from PHP. Can anyone shed >> light on why the following snippit from my menu.py doesn't work to add >> custom entries to the menu in Nuke? >> >> >> >> gizmoDir = 'Q:/Nuke_Extras/Plugins/Gizmos' >> >> gizmoList = os.listdir( gizmoDir ) >> >> for g in gizmoList: >> >> nuke.menu( 'Nodes' ).addCommand( 'Gizmos/' + >> os.path.splitext(g)[0], >> lambda: nuke.createNode(g) ) >> >> >> >> >> >> I get proper menu names for each gizmo from " 'Gizmos/' + >> os.path.splitext(g)[0] ", but "nuke.createNode(g)" always inserts the >> last gizmo from "gizmoList"... So I get a menu group that launches >> the same gizmo from multiple menu entries. >> >> >> >> I realize that this is a pretty basic thing to hit the list with, but >> I haven't had any luck finding a solution online for what (I'm >> assuming) is a simple error on my part. >> >> >> >> >> >> *Ian Haskin*** >> >> * *Sys-Admin, TOPIX >> >> ian@topixfx.com** >> >> 416-971-7711 x480 >> >> Description: topix_pong_email >> >> * www.topixfx.com * >> >> >> >> >> ---------------------------------------------------------------------- >> -- >> >> To unsubscribe from the list send a blank e-mail to >> mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=uns >> ubscribe > To unsubscribe from the list send a blank e-mail to > mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscri > be > > To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscribe > To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscribe |
||
| Re: While waiting to be added to the Foundry forums - pytho... | |||
|
Posted by: Ian Haskin ![]() Date: 04-27-2012, 13:30:PM |
That works! Your previous example got me thinking about evaluating the string, and this also works: for g in gizmoList: gizMenu = "nuke.menu( 'Nodes' ).addCommand( 'Gizmos/" + os.path.splitext(g)[0] + "', lambda: nuke.createNode('" + g + "') )" eval(gizMenu) Thanks for your help! Ian -----Original Message----- From: studiosysadmins-discuss-bounces@studiosysadmins.com [mailto:studiosysadmins-discuss-bounces@studiosysadmins.com] On Behalf Of Ott, Daniel Sent: Friday, April 27, 2012 1:19 PM To: discuss@studiosysadmins.com Subject: Re: [SSA-Discuss] While waiting to be added to the Foundry forums - python/nuke question oops yeah change "nuke.createNode('g')" % g to "nuke.createNode('%s')" % g Ian Haskin wrote: > Ok, that makes sense, however your example doesn't seem to work: TypeError: > not all arguments converted during string formatting > > I'll keep playing with it... thanks for clarifying why the same gizmo > was always loading in my example > > -----Original Message----- > From: studiosysadmins-discuss-bounces@studiosysadmins.com > [mailto:studiosysadmins-discuss-bounces@studiosysadmins.com] On Behalf > Of Ott, Daniel > Sent: Friday, April 27, 2012 12:26 PM > To: discuss@studiosysadmins.com > Subject: Re: [SSA-Discuss] While waiting to be added to the Foundry > forums - python/nuke question > > lambda just returns an unnamed function... 'nuke.createNode(g)' would > be the body of the function. 'g' won't get evaluated until you call > the function, at which point you've already iterated through the list > of gizmo's and g is left set to the last item in the list. > > One approach would be to just generate a string to be evaluated later on... > > nuke.menu( 'Nodes' ).addCommand( > 'Gizmos/' + os.path.splitext(g)[0], "nuke.createNode('g')" % g > ) > > > Daniel Ott > > > Ian Haskin wrote: >> I'm new to Python and I'm coming to it from PHP. Can anyone shed >> light on why the following snippit from my menu.py doesn't work to >> add custom entries to the menu in Nuke? >> >> >> >> gizmoDir = 'Q:/Nuke_Extras/Plugins/Gizmos' >> >> gizmoList = os.listdir( gizmoDir ) >> >> for g in gizmoList: >> >> nuke.menu( 'Nodes' ).addCommand( 'Gizmos/' + >> os.path.splitext(g)[0], >> lambda: nuke.createNode(g) ) >> >> >> >> >> >> I get proper menu names for each gizmo from " 'Gizmos/' + >> os.path.splitext(g)[0] ", but "nuke.createNode(g)" always inserts the >> last gizmo from "gizmoList"... So I get a menu group that launches >> the same gizmo from multiple menu entries. >> >> >> >> I realize that this is a pretty basic thing to hit the list with, but >> I haven't had any luck finding a solution online for what (I'm >> assuming) is a simple error on my part. >> >> >> >> >> >> *Ian Haskin*** >> >> * *Sys-Admin, TOPIX >> >> ian@topixfx.com** >> >> 416-971-7711 x480 >> >> Description: topix_pong_email >> >> * www.topixfx.com * >> >> >> >> >> --------------------------------------------------------------------- >> - >> -- >> >> To unsubscribe from the list send a blank e-mail to >> mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=un >> s >> ubscribe > To unsubscribe from the list send a blank e-mail to > mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=uns > ubscri > be > > To unsubscribe from the list send a blank e-mail to > mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=uns > ubscribe > To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscri be To unsubscribe from the list send a blank e-mail to mailto:studiosysadmins-discuss-request@studiosysadmins.com?subject=unsubscribe |
||