Skip to content

Tool to extract PSD and XCF Gimp layers #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Python_GUI/extractPSDLayers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

180 changes: 180 additions & 0 deletions Python_GUI/extractPSDLayers/extractPSDLayers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#This Source Code Form is subject to the terms of the Mozilla Public
#License, v. 2.0. If a copy of the MPL was not distributed with this
#file, You can obtain one at http://mozilla.org/MPL/2.0/. */
# Derived from Fabrice Fernandez extractEXRLayers. Implemented by CGVIRUS

import os
import string
import NatronEngine
from NatronGui import *


# EXTRACT PSD LAYERS #

def extractPSDLayers():

# get current Natron instance running in memory #
app = natron.getGuiInstance(0)

# get selected nodes #
selectedNodes = app.getSelectedNodes()

# cycle through every selected node #
for currentNode in selectedNodes:

# get node ID #
currentID = currentNode.getPluginID()

# check if selected node is a 'Read' node #
if currentID == 'fr.inria.built-in.Read':

# get 'Read' node position #
readPosition = currentNode.getPosition()




###################
# CREATE ROOT DOT #
###################

# create root dot #
rootDot = app.createNode('fr.inria.built-in.Dot')

# set root dot position #
rootDot.setPosition(readPosition[0] + 45 , readPosition[1] + 300)

# connect root dot to 'Read' #
rootDot.connectInput(0,currentNode)

# get root dot position #
rootDotPosition = rootDot.getPosition()





# get all available layers in PSD #
if hasattr(currentNode.getParam('layer'),'getOptions'):
layersList = currentNode.getParam('layer').getOptions()
else:
layersList = currentNode.getParam('outputLayer').getOptions()

# sort list alphabetically #
list.sort(layersList)

backdropLength = len(layersList)

# initialize counter #
channelCounter = 0

# cycle through every layer #
for choice in layersList:

if choice != 'Default' or 'Color.RGBA':

# full layer name #
LayerName = choice

# layer name #
layerName = os.path.splitext(choice)[0]

print layerName

# layer channels (RGBA,RGB,XYZ,UV,A,Z) #
layerChannels = os.path.splitext(choice)[1]

# remove '.' from channels #
layerChannels = layerChannels.replace('.','')




# create the first 'Shuffle' node #
if channelCounter == 0 :

###################
# CREATE SHUFFLE #
###################

# create a 'Shuffle' node #
newShuffle = app.createNode('net.sf.openfx.ShufflePlugin')

# set 'Shuffle' label #
newShuffle.setLabel(str(layerName))

# enable preview #
newShuffle.getParam('enablePreview').setValue(1)
newShuffle.getParam('enablePreview').setValue(0)
newShuffle.getParam('enablePreview').setValue(1)

# set 'Shuffle' node position #
newShuffle.setPosition(rootDotPosition[0] - 45 , rootDotPosition[1] + 200)

# set 'Shuffle' color #
newShuffle.setColor(1, 0.5, 0.15)

# connect 'Shuffle' to root dot #
newShuffle.connectInput(0,rootDot)

# create a 'Backdrop' #
newBackdrop = app.createNode('fr.inria.built-in.BackDrop')
newBackdrop.setPosition(rootDotPosition[0] - 200 , rootDotPosition[1] - 120)
newBackdrop.setSize( (backdropLength)*400, 500 )
newBackdrop.setColor(0.5, 0.35, 0.12)


# create all the other 'Shuffle' nodes #
if channelCounter != 0 :

# create a new dot #
newDot = app.createNode('fr.inria.built-in.Dot')

# set root dot position #
newDot.setPosition(rootDotPosition[0] + 400 , rootDotPosition[1])

# connect root dot to previous dot #
newDot.connectInput(0,rootDot)

# replace old Dot position value
rootDotPosition = newDot.getPosition()


###################
# CREATE SHUFFLE #
###################


# create a 'Shuffle' node #
newShuffle = app.createNode('net.sf.openfx.ShufflePlugin')

# set 'Shuffle' label #
newShuffle.setLabel(str(layerName))

# enable preview #
newShuffle.getParam('enablePreview').setValue(1)
newShuffle.getParam('enablePreview').setValue(0)
newShuffle.getParam('enablePreview').setValue(1)

# set 'Shuffle' node position #
newShuffle.setPosition(rootDotPosition[0] - 45 , rootDotPosition[1] + 200)

# set 'Shuffle' color #
newShuffle.setColor(1, 0.5, 0.15)

# connect 'Shuffle' to root dot #
newShuffle.connectInput(0,newDot)




##########################
# SET SHUFFLE PARAMETERS #
##########################

newShuffleValue = 'B.' + str(layerName) + '.' + 'R'
newShuffle.getParam('outputR').set(newShuffleValue)


# increase counter #
channelCounter += 1
7 changes: 5 additions & 2 deletions initGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# Tools -> Channel
from Python_GUI.autoAlpha.autoAlpha import *
from Python_GUI.extractExrLayers.extractExrLayers import *
from Python_GUI.extractPSDLayers.extractPSDLayers import *

# Tools -> Generate
from Python_GUI.postageStamp.postageStamp import *
Expand Down Expand Up @@ -86,6 +87,7 @@

NatronGui.natron.addMenuCommand('Tools/Channel/Auto alpha','autoAlpha')
NatronGui.natron.addMenuCommand('Tools/Channel/Extract EXR layers','extractExrLayers')
NatronGui.natron.addMenuCommand('Tools/Channel/Extract PSD or XCF layers','extractPSDLayers')

NatronGui.natron.addMenuCommand('Tools/Generate/PostageStamp','postageStamp', QtCore.Qt.Key.Key_P, QtCore.Qt.KeyboardModifier.ControlModifier | QtCore.Qt.AltModifier)
NatronGui.natron.addMenuCommand('Tools/Generate/Roto to tracker','rotoToTracker')
Expand All @@ -104,8 +106,8 @@
NatronGui.natron.addMenuCommand('Edit/Invert selection','invertSelection', QtCore.Qt.Key.Key_I, QtCore.Qt.KeyboardModifier.ControlModifier | QtCore.Qt.ShiftModifier)
NatronGui.natron.addMenuCommand('Edit/Remove input','removeInput', QtCore.Qt.Key.Key_D, QtCore.Qt.KeyboardModifier.ControlModifier)

NatronGui.natron.addMenuCommand('Tools/Other/Blending mode+','mergeBlendingDown', QtCore.Qt.Key.Key_Down, QtCore.Qt.KeyboardModifier)
NatronGui.natron.addMenuCommand('Tools/Other/Blending mode-','mergeBlendingUp', QtCore.Qt.Key.Key_Up, QtCore.Qt.KeyboardModifier)
NatronGui.natron.addMenuCommand('Tools/Other/Blending mode+','mergeBlendingDown', QtCore.Qt.Key.Key_Down, QtCore.Qt.AltModifier)
NatronGui.natron.addMenuCommand('Tools/Other/Blending mode-','mergeBlendingUp', QtCore.Qt.Key.Key_Up, QtCore.Qt.AltModifier)
NatronGui.natron.addMenuCommand('Tools/Other/Link roto to tracker','rotoLink', QtCore.Qt.Key.Key_L, QtCore.Qt.KeyboardModifier.ControlModifier | QtCore.Qt.ShiftModifier)

NatronGui.natron.addMenuCommand('Tools/Roto/Circle','fullCircle()')
Expand Down Expand Up @@ -143,6 +145,7 @@
print '\n'
print ' + Tools/Channel/Auto Alpha'
print ' + Tools/Channel/Extract EXR layers'
print ' + Tools/Channel/Extract PSD/XCF layers'
print ' +'
print ' + Tools/Generate/PostageStamp'
print ' + Tools/Generate/Roto to tracker'
Expand Down