Example #1
0
    def execute(self):
        if fx.selection() == []:
            displayError("KMFXNode Time Offset: Select some nodes",
                         title="Error")
            return

        num = {"id": "num", "label": "Frames to offset", "value": 0}
        direction = {
            "id": "list",
            "label": "Direction",
            "value": "Head",
            "items": ["Head", "Tail"]
        }

        fields = [num, direction]
        result = getInput(title="Offset Node Keyframes", fields=fields)

        if result != None:
            fx.beginUndo("KMFX Node time offset")

            offset = result['num'] * -1 if result[
                "list"] == "Head" else result['num']

            nodes = fx.selection()
            for node in nodes:
                if node.isType("PaintNode"):
                    pass  ## cant change paint nodes at this time

                elif node.type in ["RotoNode", "MorphNode"]:
                    child = node.children
                    objects = getObjects(child)
                    selectedlist = []  ## selection is just to refresh timeline

                    for o in objects:
                        if o.selected == True:
                            selectedlist.append(o)

                        for p in o.properties:
                            if o.property(p).constant != True:
                                o.property(p).moveKeys(offset)

                ### this is for all nodes properties

                for p in node.properties:
                    if node.property(p).constant != True:
                        node.property(p).moveKeys(offset)
                x = fx.selection()
                fx.select([])
                fx.select(x)

            fx.endUndo()
Example #2
0
def SnapToGrid():
    import fx

    tool = 'Snap to Grid'
    PrintStatus(tool)
    fx.beginUndo(tool)

    # Get the Project
    project = fx.activeProject()

    # Get the node selection
    sel = fx.selection()

    # Padding width for node count
    padding = len(str(len(sel)))

    i = 0
    for node in sel:
        i = i + 1
        # The node.state dict holds {'viewMode': 0, 'graph.pos': Point3D(394.641,22.4925)}
        if node.state is not None:
            # The Point3D(0,0) datatype has .x and .y attributes
            pos = node.state.items()[1][1]
            if pos is not None:
                # Snap the nodes to a 10 unit grid
                #snapX = round(pos.x, -1)
                #snapY = round(pos.y, -1)

                # Snap to 50 grid units
                snapX = round(float(pos.x) * 2, -2) * 0.5
                snapY = round(float(pos.y) * 2, -2) * 0.5

                # Snap to 100 grid units on X and 50 gird units on Y
                snapX = round(pos.x, -2)
                snapY = round(float(pos.y) * 2, -2) * 0.5

                # Snap the nodes to a 100 unit grid
                #snapX = round(pos.x, -2)
                #snapY = round(pos.y, -2)

                # Update the grid snapped node position
                node.setState('graph.pos', fx.Point3D(snapX, snapY))

                posUpdate = node.state.items()[1][1]
                if posUpdate is not None:
                    print('[' + str(i).zfill(padding) + '] ' +
                          str(node.label) + ' [Original] [X]' + str(pos.x) +
                          ' [Y] ' + str(pos.y) + ' [Updated] [X]' +
                          str(posUpdate.x) + ' [Y] ' + str(posUpdate.y))

    fx.endUndo()

    # SaveProject()

    # hide the window
    snapWindow.hide()
Example #3
0
def StackVertical():
    import fx

    tool = 'Stack Vertical'
    PrintStatus(tool)
    fx.beginUndo(tool)

    # Get the Project
    project = fx.activeProject()

    # Get the node selection
    sel = fx.selection()

    # Padding width for node count
    padding = len(str(len(sel)))

    # Spacing distance between stacked nodes
    nodeSpacing = 100

    # Use the first selected object as a reference for the Node Y position
    referenceY = 0
    if len(sel) > 0:
        referenceY = sel[0].state.items()[1][1].y
        print('[Reference Y] ' + str(referenceY))

        # Scan all of the selected nodes
        i = 0
        for node in sel:
            # The node.state dict holds {'viewMode': 0, 'graph.pos': Point3D(394.641,22.4925)}
            if (node.state is not None) and (node != sel[0]):
                i = i + 1
                # The Point3D(0,0) datatype has .x and .y attributes
                pos = node.state.items()[1][1]
                if pos is not None:
                    # Stack the nodes side by side
                    node.setState(
                        'graph.pos',
                        fx.Point3D(pos.x, (referenceY + (i * nodeSpacing))))

                    # Read back the results
                    posUpdate = node.state.items()[1][1]
                    if posUpdate is not None:
                        print('[' + str(i).zfill(padding) + '] ' +
                              str(node.label) + ' [Original] [X]' +
                              str(pos.x) + ' [Y] ' + str(pos.y) +
                              ' [Updated] [X]' + str(posUpdate.x) + ' [Y] ' +
                              str(posUpdate.y))
    else:
        print('[Error] Please select 2 or more nodes.')

    fx.endUndo()

    # SaveProject()

    # hide the window
    snapWindow.hide()
Example #4
0
def AlignHorizontal():
    import fx

    tool = 'Align Horizontal'
    PrintStatus(tool)
    fx.beginUndo(tool)

    # Get the Project
    project = fx.activeProject()

    # Get the node selection
    sel = fx.selection()

    # Padding width for node count
    padding = len(str(len(sel)))

    # Use the first selected object as a reference for the Node X position
    referenceX = 0
    if len(sel) > 0:
        referenceX = sel[0].state.items()[1][1].x
        print('[Reference X] ' + str(referenceX))

        # Scan all of the selected nodes
        i = 0
        for node in sel:
            i = i + 1
            # The node.state dict holds {'viewMode': 0, 'graph.pos': Point3D(394.641,22.4925)}
            if node.state is not None:
                # The Point3D(0,0) datatype has .x and .y attributes
                pos = node.state.items()[1][1]
                if pos is not None:
                    # Snap all the nodes to the same X height
                    node.setState('graph.pos', fx.Point3D(referenceX, pos.y))

                    # Read back the results
                    posUpdate = node.state.items()[1][1]
                    if posUpdate is not None:
                        print('[' + str(i).zfill(padding) + '] ' +
                              str(node.label) + ' [Original] [X]' +
                              str(pos.x) + ' [Y] ' + str(pos.y) +
                              ' [Updated] [X]' + str(posUpdate.x) + ' [Y] ' +
                              str(posUpdate.y))
    else:
        print('[Error] Please select 2 or more nodes.')

    fx.endUndo()

    # SaveProject()

    # hide the window
    snapWindow.hide()
Example #5
0
def AlignByCSV():
    import fx
    import csv

    path = '/Applications/SilhouetteFX/Silhouette v7.5/Silhouette.app/Contents/Resources/scripts/node_shape.csv'

    tool = 'Align By CSV'
    PrintStatus(tool)
    fx.beginUndo(tool)

    # Get the Project
    project = fx.activeProject()

    # Get the node selection
    sel = fx.selection()

    # Padding width for node count
    padding = 4

    # How many nodes are selected
    count = len(sel)

    # Prepare CSV reading
    with open(path, 'rb') as fp:
        reader = csv.reader(fp, delimiter=',')

        i = 0
        # Scan all of the selected nodes
        for row in reader:
            # Move onto the next node
            # The node.state dict holds {'viewMode': 0, 'graph.pos': Point3D(394.641,22.4925)}
            if i < count:
                node = sel[i]
                if (node.state is not None):
                    # The Point3D(0,0) datatype has .x and .y attributes
                    node.setState('graph.pos',
                                  fx.Point3D(float(row[0]), float(row[1])))

                    #posUpdate = node.state.items()[1][1]
                    #if posUpdate is not None:
                    # Read back the results
                    # print('{0},{1:.03f},{2:.03f}'.format(str(i).zfill(padding), posUpdate.x, posUpdate.y))
            i = i + 1

    fx.endUndo()

    # SaveProject()

    # hide the window
    snapWindow.hide()
    def execute(self):
        fx.beginUndo("Paint Hard Alpha setup")
        basenode = fx.selection()
        pos = basenode[0].state["graph.pos"]

        creatednodes = []
        if len(basenode) == 1:
            base = basenode[0]
            n1 = Node("com.digitalfilmtools.ofx.silhouette.sfx_copy")

            creatednodes.append(n1)
            activeSession().addNode(n1)
            try:
                n1.port("source").connect(base.port("output"))
                n1.port("target").connect(base.port("output"))
            except Exception:
                pass
            n1.property("red").setValue("Alpha")
            n1.property("blue").setValue("Alpha")
            n1.property("green").setValue("Alpha")

            """ setting the state (pos) for fresh nodes should be done inside a
             fx.beginUndo, otherwise the node Tree won't update correctly. """
            n1.setState('graph.pos', fx.Point3D(pos.x+150, pos.y))

            nn1 = n1
            for n in range(0, 4):
                n2 = Node("com.digitalfilmtools.ofx.silhouette.colorCorrect")
                activeSession().addNode(n2)
                n2.port("input").connect(nn1.port("Output"))
                n2.property("gamma").setValue(100)
                creatednodes.append(n2)
                n2.setState('graph.pos', fx.Point3D(
                    pos.x+150, pos.y+(50*(n+1))))
                nn1 = n2

            n3 = Node("com.digitalfilmtools.ofx.silhouette.sfx_copy")
            activeSession().addNode(n3)
            n3.port("source").connect(n2.port("Output"))
            n3.port("target").connect(base.port("output"))
            n3.property("alpha").setValue("Red")
            n3.setState('graph.pos', fx.Point3D(pos.x+150, pos.y+(50*5)))
            creatednodes.append(n3)

        fx.endUndo()
Example #7
0
def SaveByCSV():
    import fx
    import csv

    path = '/Applications/SilhouetteFX/Silhouette v7.5/Silhouette.app/Contents/Resources/scripts/node_shape.csv'

    # Prepare CSV writing
    with open(path, 'wb') as fp:
        writer = csv.writer(fp, delimiter=',')
        # writer.writerow(['X', 'Y'])

        tool = 'Save CSV'
        PrintStatus(tool)
        fx.beginUndo(tool)

        # Get the Project
        project = fx.activeProject()

        # Get the node selection
        sel = fx.selection()

        # Padding width for node count
        padding = len(str(len(sel)))

        if len(sel) > 1:
            # Scan all of the selected nodes
            for node in sel:
                # The node.state dict holds {'viewMode': 0, 'graph.pos': Point3D(394.641,22.4925)}
                if node.state is not None:
                    # The Point3D(0,0) datatype has .x and .y attributes
                    pos = node.state.items()[1][1]
                    if pos is not None:
                        # Read back the results
                        # print('{0:.03f},{1:.03f}'.format(pos.x, pos.y))
                        writer.writerow([pos.x, pos.y])
        else:
            print('[Error] Please select 2 or more nodes.')

        fx.endUndo()
def run():
    import fx

    print(
        '\n\n---------------------------------------------------------------------------------'
    )
    print('Node Explorer')

    # Get the node selection
    sel = fx.selection()

    # Scan through all of the nodes
    for s in sel:
        print(
            '\n---------------------------------------------------------------------------------\n'
        )
        print('[Node] ' + str(s) + '\n')
        # List all properties
        for i in range(len(s.properties.keys())):
            key = s.properties.keys()[i]
            print('\t[Propery] ' + str(key) + ' [Value] "' +
                  str(s.properties[key].value) + '"')
Example #9
0
 def available(self):
     assert fx.selection() != [], "Select some nodes"
Example #10
0
def DistributeSpacesHorizontal():
    import fx

    tool = 'Distribute Spaces Horizontal'
    PrintStatus(tool)
    fx.beginUndo(tool)

    # Get the Project
    project = fx.activeProject()

    # Get the node selection
    sel = fx.selection()

    # Padding width for node count
    padding = len(str(len(sel)))

    # How many does were selected
    nodeCount = len(sel)

    # Use the first selected object as a reference for the Node position
    referenceStartX = 0
    referenceEndX = 0
    if nodeCount > 0:
        print('[Selected Nodes] ' + str(nodeCount))

        referenceStartX = sel[0].state.items()[1][1].x
        print('[Reference Start X] ' + str(referenceStartX))

        referenceEndX = sel[nodeCount - 1].state.items()[1][1].x
        print('[Reference End X] ' + str(referenceEndX))

        # Start/End Node Distance
        nodeDistance = abs(referenceStartX - referenceEndX)
        print('[Node Distance X] ' + str(nodeDistance))

        # Spacing distance between stacked nodes
        nodeSpacing = (nodeDistance) / (nodeCount - 1)
        print('[Node Spacing X] ' + str(nodeSpacing))

        # Scan all of the selected nodes
        i = 0
        for node in sel:
            # The node.state dict holds {'viewMode': 0, 'graph.pos': Point3D(394.641,22.4925)}
            if (node.state is not None) and (node != sel[0]) and (
                    node != sel[nodeCount - 1]):
                # if (node.state is not None):
                i = i + 1
                # The Point3D(0,0) datatype has .x and .y attributes
                pos = node.state.items()[1][1]
                if pos is not None:
                    # Stack the nodes side by side
                    node.setState(
                        'graph.pos',
                        fx.Point3D((referenceStartX + (i * nodeSpacing)),
                                   pos.y))

                    # Read back the results
                    posUpdate = node.state.items()[1][1]
                    if posUpdate is not None:
                        print('[' + str(i).zfill(padding) + '] ' +
                              str(node.label) + ' [Original] [X]' +
                              str(pos.x) + ' [Y] ' + str(pos.y) +
                              ' [Updated] [X]' + str(posUpdate.x) + ' [Y] ' +
                              str(posUpdate.y))
    else:
        print('[Error] Please select 2 or more nodes.')

    fx.endUndo()

    # SaveProject()

    # hide the window
    snapWindow.hide()