class layoutNodes(KellerNukePlugin):

    def configurePlugin(self):
        self.menu = nuke.menu("Nuke")
        m = self.menu.addMenu("Workgroup")
        m.addCommand("Layout Nodes", "import layoutNodes; layoutNodes.doLayoutNodes()", 'shift+l')

    def unconfigurePlugin(self):
        self.menu.removeItem("layoutNodes")
        pass


def doLayoutNodes():
    import nuke

    try:
        sel = nuke.selectedNodes()
    except:
        sel = None

    if sel:
        if len(sel) > 1:
            dist = sel[len(sel) - 1].xpos() - sel[len(sel) - 2].xpos()
            #print "LayoutNodes: Offset %s Pixels" % dist
        offset = dist
        fac = 1.15
        i = 0
        for node in sel:
            if i == 0:
                initposx = node.xpos()
                initposy = node.ypos()
            else:
                # margin = margin + margin
                node.setXYpos(int((initposx + i * offset * fac)), int(initposy))
            i = i + 1
    return None