If you want the center of a selection of nodes you could do something like:
sn = nuke.selectedNodes() xp = [n.xpos() for n in sn] yp = [n.ypos() for n in sn] wa = sum([n.screenWidth() for n in sn])/len(xp) # node width average ha = sum([n.screenHeight() for n in sn])/len(xp) # node height average cx = int(min(xp)+((max(xp)-min(xp))*0.5)-(wa/2)) # selected x center cy = int(min(yp)+((max(yp)-min(yp))*0.5)-(ha/2)) # selected y center # position offset xo = 0 yo = 100 n = nuke.nodes.Blur() n.setXpos(cx+xo) n.setYpos(cy+yo) On Thu, Mar 16, 2017 at 6:48 PM, Rich Bobo <richb...@mac.com> wrote: > Darren, > > I see you’ve edited the function to only return only the X position value… > I’m not sure why you are doing that and I don’t have time to look at the > rest of the code at the moment, but if you use the function “as is", it > works. > > If you only want one of the values, bind the resulting list to a > variable... > > centerXYpos = nodeList_center() > > …and get the x or y value you want with its list index number... > > centerXYpos[0] # X value > centerXYpos[1] # Y value > > Does the make sense? > > Rich > > > On Mar 16, 2017, at 5:24 PM, Darren Coombes <darren.coom...@me.com> wrote: > > Thanks Rich. > I can’t seem to get it to work. > > Here’s the full script.. Feel free to use it if you can get the centre > node part working. > > > # v2.3 march 2017 > > import nuke > import os > > > n=nuke.selectedNodes() > > # delete all Viewer Nodes (so they dont get included in groups later on) > def deleteViewer(): > for n in nuke.allNodes('Viewer'): > nuke.delete(n) > > > # arrange all nodes neatly using autoplace command > def cleanUp(): > nuke.selectAll() > for n in nuke.selectedNodes(): > nuke.autoplace(n) > > > > # looks for all read nodes, then creates node labelthumb under each read > def addlt(): > # adds a certain node under each "Read" Node = Filters Node Class > "Read" > sn = nuke.selectedNodes("Read") > > if sn == []: > sn = nuke.allNodes("Read") > if sn == []: > nuke.message("No Read nodes found") > else: > for n in sn: > n.knob("selected").setValue(True) > nuke.createNode("LabelThumb", "", False) > > > #selects all LabelThumb Nodes > def allLT(): > for n in nuke.allNodes('Group'): > n['selected'].setValue(True) > > > > > # find x center point for next node creation > def nodeList_center(nodeList=None): > '''Node placement function, from Drew Loveridge...''' > if nodeList == None: > nodeList=nuke.selectedNodes() > nNodes = len(nodeList) > x=0 > for n in nodeList: > x += n.xpos() > try: > return [x/nNodes] > except ZeroDivisionError: > return [0] > print nodeList_center() > nodeList_center() > > > > nlist = nodeList_center() > print nlist > > # create contactsheet node with a gap of 20 > def createCS(): > cs = nuke.createNode('ContactSheet') > cs['gap'].setValue(20) > cs['center'].setValue(True) > cs['label'].setValue("inputs: [value inputs]") > # cs.knob('xpos').setValue(nlist) > cs.setXpos(nlist[0]) > > > ## creates a group of all selected nodes.. > #selects all LabelThumb Nodes > def mkGroup(): > nuke.selectAll() > nuke.collapseToGroup() > > def addKnobs(): > g = nuke.selectedNode() > k = nuke.Enumeration_Knob("listfiles", "files", ['red', 'green', > 'blue']) > g.addKnob(k) > > > > > > > def addLabelThumb(): > deleteViewer() > cleanUp() > addlt() > allLT() > nodeList_center() > createCS() > #mkGroup() > > > > > > > > > *Check out some of my work…* > *www.vimeo.com/darrencoombes/reel2017* > <http://www.vimeo.com/darrencoombes/reel2017> > > *Mob: **+61 418 631 079* <+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* > > On 17 Mar 2017, at 7:51 am, Rich Bobo <richb...@mac.com> wrote: > > cs.setXYpos(center[0], center[1]+300) > > > _______________________________________________ > 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 >
_______________________________________________ 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