Try this:
Now you get the real center, and when you dont select anything it takes all nodes into account, otherwise just the selection.

Cheers

def center_and_below():

     if len(nuke.selectedNodes()) == 0:

nodeList = nuke.allNodes()

     else:

nodeList = nuke.selectedNodes()


     xList = []

     yList = []


     for n in nodeList:

xList.append(n.xpos())

yList.append(n.ypos())


xList.sort()

    x = get_center(xList)

yList.sort()

    y = yList[-1]+100


return x, y



def get_center(your_list):

     val = ((your_list[-1] - your_list[0]) / 2) + your_list[0]


return val



def createCS():

     cs = nuke.createNode('ContactSheet')

cs['gap'].setValue(20)

cs['center'].setValue(True)

center_pos = center_and_below()

cs.setXpos(center_pos[0])

cs.setYpos(center_pos[1])


createCS()


Am 16.03.2017 um 06:22 schrieb Darren Coombes:
Thanks Rich,

so if i create a ContactSheet node and i want to set its xpos to the result of the nodeList_center()
i can’t seem to figure that part out.

i’m creating the node this way.


def nodeList_center(nodeList=None):
    '''Node placement function, from Drew Loveridge...'''
    if nodeList == None:
        nodeList=nuke.selectedNodes()
    nNodes = len(nodeList)
    x=0
    y=0
    for n in nodeList:
        x += n.xpos()
    for n in nodeList:
        y += n.ypos()
    try:
        return [x/nNodes,y/nNodes]
    except ZeroDivisionError:
        return [0,0]

def createCS():
cs = nuke.createNode("ContactSheet”)
cs[‘gap’].setValue(20)
cs[‘center’].setValue(True)
cs.knob.(‘xpos’)setValue(nodeList_center) ### this part not working, my syntax not great.
createCS()

*Check out some of my work…*
*www.vimeo.com/darrencoombes/reel2017* <http://www.vimeo.com/darrencoombes/reel2017>

*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*

On 16 Mar 2017, at 2:21 pm, Rich Bobo <[email protected] <mailto:[email protected]>> wrote:

Darren,

I can’t take credit for this; it’s from my co-worker, Drew Loveridge…

— If you don’t give it a list of nodes, it will use the currently selected nodes as the default list. — It returns a list, for example: [26, -458] -- which is the center x, y position of the node list. Then, you can create your new node and use those values to set the XYPosition for the node, probably with an offset on Y... I use it all the time!


def nodeList_center(nodeList=None):
    '''Node placement function, from Drew Loveridge...'''
    if nodeList == None:
nodeList=nuke.selectedNodes()
    nNodes = len(nodeList)
    x=0
    y=0
    for n in nodeList:
        x += n.xpos()
    for n in nodeList:
        y += n.ypos()
    try:
        return [x/nNodes,y/nNodes]
    except ZeroDivisionError:
        return [0,0]


Rich


Rich Bobo
Senior VFX Compositor
Armstrong White
Email: [email protected] <mailto:[email protected]>
http://armstrong-white.com/

Email: [email protected] <mailto:[email protected]>
Mobile:  (248) 840-2665
Web: http://richbobo.com/

"A professional is someone who can do his best work when he doesn't feel like it."
- Alistair Cooke


On Mar 15, 2017, at 10:07 PM, Darren Coombes <[email protected] <mailto:[email protected]>> wrote:

How can i find out the centre co-ordinate of say, 9 selected nodes, so i can create a node that’s directly below

nodes = nuke.selectedNodes()
amount = len(nodes)
center = ?? this where i’m stuck, need to get the value.

nuke.nodes.ContactSheet(xpos=center)

any help, greatly appreciated.
Thanks.

Darren.


*Check out some of my work…*
*www.vimeo.com/darrencoombes/reel2017* <http://www.vimeo.com/darrencoombes/reel2017>

*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://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users

_______________________________________________
Nuke-users mailing list
[email protected] <mailto:[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

--
--------------
Igor Majdandzic
Compositing Supervisor/TD

@Chimney Frankfurt

_______________________________________________
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