|
| 1 | +#This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +#License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +#file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | +# Derived from Fabrice Fernandez extractEXRLayers. Implemented by CGVIRUS |
| 5 | + |
| 6 | +import os |
| 7 | +import string |
| 8 | +import NatronEngine |
| 9 | +from NatronGui import * |
| 10 | + |
| 11 | + |
| 12 | +# EXTRACT PSD LAYERS # |
| 13 | + |
| 14 | +def extractPSDLayers(): |
| 15 | + |
| 16 | + # get current Natron instance running in memory # |
| 17 | + app = natron.getGuiInstance(0) |
| 18 | + |
| 19 | + # get selected nodes # |
| 20 | + selectedNodes = app.getSelectedNodes() |
| 21 | + |
| 22 | + # cycle through every selected node # |
| 23 | + for currentNode in selectedNodes: |
| 24 | + |
| 25 | + # get node ID # |
| 26 | + currentID = currentNode.getPluginID() |
| 27 | + |
| 28 | + # check if selected node is a 'Read' node # |
| 29 | + if currentID == 'fr.inria.built-in.Read': |
| 30 | + |
| 31 | + # get 'Read' node position # |
| 32 | + readPosition = currentNode.getPosition() |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + ################### |
| 38 | + # CREATE ROOT DOT # |
| 39 | + ################### |
| 40 | + |
| 41 | + # create root dot # |
| 42 | + rootDot = app.createNode('fr.inria.built-in.Dot') |
| 43 | + |
| 44 | + # set root dot position # |
| 45 | + rootDot.setPosition(readPosition[0] + 45 , readPosition[1] + 300) |
| 46 | + |
| 47 | + # connect root dot to 'Read' # |
| 48 | + rootDot.connectInput(0,currentNode) |
| 49 | + |
| 50 | + # get root dot position # |
| 51 | + rootDotPosition = rootDot.getPosition() |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + # get all available layers in PSD # |
| 58 | + if hasattr(currentNode.getParam('layer'),'getOptions'): |
| 59 | + layersList = currentNode.getParam('layer').getOptions() |
| 60 | + else: |
| 61 | + layersList = currentNode.getParam('outputLayer').getOptions() |
| 62 | + |
| 63 | + # sort list alphabetically # |
| 64 | + list.sort(layersList) |
| 65 | + |
| 66 | + backdropLength = len(layersList) |
| 67 | + |
| 68 | + # initialize counter # |
| 69 | + channelCounter = 0 |
| 70 | + |
| 71 | + # cycle through every layer # |
| 72 | + for choice in layersList: |
| 73 | + |
| 74 | + if choice != 'Default' or 'Color.RGBA': |
| 75 | + |
| 76 | + # full layer name # |
| 77 | + LayerName = choice |
| 78 | + |
| 79 | + # layer name # |
| 80 | + layerName = os.path.splitext(choice)[0] |
| 81 | + |
| 82 | + print layerName |
| 83 | + |
| 84 | + # layer channels (RGBA,RGB,XYZ,UV,A,Z) # |
| 85 | + layerChannels = os.path.splitext(choice)[1] |
| 86 | + |
| 87 | + # remove '.' from channels # |
| 88 | + layerChannels = layerChannels.replace('.','') |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + # create the first 'Shuffle' node # |
| 94 | + if channelCounter == 0 : |
| 95 | + |
| 96 | + ################### |
| 97 | + # CREATE SHUFFLE # |
| 98 | + ################### |
| 99 | + |
| 100 | + # create a 'Shuffle' node # |
| 101 | + newShuffle = app.createNode('net.sf.openfx.ShufflePlugin') |
| 102 | + |
| 103 | + # set 'Shuffle' label # |
| 104 | + newShuffle.setLabel(str(layerName)) |
| 105 | + |
| 106 | + # enable preview # |
| 107 | + newShuffle.getParam('enablePreview').setValue(1) |
| 108 | + newShuffle.getParam('enablePreview').setValue(0) |
| 109 | + newShuffle.getParam('enablePreview').setValue(1) |
| 110 | + |
| 111 | + # set 'Shuffle' node position # |
| 112 | + newShuffle.setPosition(rootDotPosition[0] - 45 , rootDotPosition[1] + 200) |
| 113 | + |
| 114 | + # set 'Shuffle' color # |
| 115 | + newShuffle.setColor(1, 0.5, 0.15) |
| 116 | + |
| 117 | + # connect 'Shuffle' to root dot # |
| 118 | + newShuffle.connectInput(0,rootDot) |
| 119 | + |
| 120 | + # create a 'Backdrop' # |
| 121 | + newBackdrop = app.createNode('fr.inria.built-in.BackDrop') |
| 122 | + newBackdrop.setPosition(rootDotPosition[0] - 200 , rootDotPosition[1] - 120) |
| 123 | + newBackdrop.setSize( (backdropLength)*400, 500 ) |
| 124 | + newBackdrop.setColor(0.5, 0.35, 0.12) |
| 125 | + |
| 126 | + |
| 127 | + # create all the other 'Shuffle' nodes # |
| 128 | + if channelCounter != 0 : |
| 129 | + |
| 130 | + # create a new dot # |
| 131 | + newDot = app.createNode('fr.inria.built-in.Dot') |
| 132 | + |
| 133 | + # set root dot position # |
| 134 | + newDot.setPosition(rootDotPosition[0] + 400 , rootDotPosition[1]) |
| 135 | + |
| 136 | + # connect root dot to previous dot # |
| 137 | + newDot.connectInput(0,rootDot) |
| 138 | + |
| 139 | + # replace old Dot position value |
| 140 | + rootDotPosition = newDot.getPosition() |
| 141 | + |
| 142 | + |
| 143 | + ################### |
| 144 | + # CREATE SHUFFLE # |
| 145 | + ################### |
| 146 | + |
| 147 | + |
| 148 | + # create a 'Shuffle' node # |
| 149 | + newShuffle = app.createNode('net.sf.openfx.ShufflePlugin') |
| 150 | + |
| 151 | + # set 'Shuffle' label # |
| 152 | + newShuffle.setLabel(str(layerName)) |
| 153 | + |
| 154 | + # enable preview # |
| 155 | + newShuffle.getParam('enablePreview').setValue(1) |
| 156 | + newShuffle.getParam('enablePreview').setValue(0) |
| 157 | + newShuffle.getParam('enablePreview').setValue(1) |
| 158 | + |
| 159 | + # set 'Shuffle' node position # |
| 160 | + newShuffle.setPosition(rootDotPosition[0] - 45 , rootDotPosition[1] + 200) |
| 161 | + |
| 162 | + # set 'Shuffle' color # |
| 163 | + newShuffle.setColor(1, 0.5, 0.15) |
| 164 | + |
| 165 | + # connect 'Shuffle' to root dot # |
| 166 | + newShuffle.connectInput(0,newDot) |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + ########################## |
| 172 | + # SET SHUFFLE PARAMETERS # |
| 173 | + ########################## |
| 174 | + |
| 175 | + newShuffleValue = 'B.' + str(layerName) + '.' + 'R' |
| 176 | + newShuffle.getParam('outputR').set(newShuffleValue) |
| 177 | + |
| 178 | + |
| 179 | + # increase counter # |
| 180 | + channelCounter += 1 |
0 commit comments