Revision: 65364
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 25, 2013 03:36 by janusoo
Initial Code
#------------------------------------------------------------------------------- # Name: LayerSetsExporter # Purpose: export files with each layer set # # Author: JanusHuang # # Created: 24/11/2013 # Copyright: (c) JanusHuang 2013 # Licence: <your licence> #------------------------------------------------------------------------------- import sys from PyQt4.QtGui import * import comtypes.client class LayerSetsExporter(QWidget): def __init__(self, parent = None): super(LayerSetsExporter, self).__init__(parent) self.outputPath = '' self.createLayout() self.createConnection() def setLayerSetsVisible(self, layerSets, state): for layerSet in layerSets: layerSet.visible = False def saveLayerSetsVisible(self, layerSets): self.origLayerSetsVisible = [] for layerSet in layerSets: self.origLayerSetsVisible.append([layerSet, layerSet.visible]) def resetLayerSetsVisible(self): for (layerSet, visible) in self.origLayerSetsVisible: layerSet.visible = visible def getExportFileName(self, layerSet): newStr = layerSet.name.replace(self.leLayerPrefix.text(), '') return newStr def setOutputPath(self): self.outputPath = str(QFileDialog.getExistingDirectory(self, "Select Directory")) + '\\' self.leOutputPath.setText(self.outputPath) def processRun(self): app = comtypes.client.CreateObject('Photoshop.Application') doc = app.activeDocument if self.leOutputPath.text() == '': self.outputPath = doc.path self.leOutputPath.setText(self.outputPath) optionJpg = comtypes.client.CreateObject('Photoshop.JPEGSaveOptions') optionJpg.quality = 8 count = 1 layerSets = doc.layerSets #self.pbProcessing.setMaximum(layerSets.length) self.saveLayerSetsVisible(layerSets) for layerSet in layerSets: if self.leLayerPrefix.text() in layerSet.name: self.setLayerSetsVisible(layerSets, False) layerSet.visible = True doc.saveAs(self.outputPath + self.getExportFileName(layerSet) + '.jpg', optionJpg, True) self.pbProcessing.setValue(count) count += 1 self.resetLayerSetsVisible() self.pbProcessing.reset() def createLayout(self): lblLayerPrefix = QLabel('Layer Prefix :') self.leLayerPrefix = QLineEdit('ept_') layoutH1 = QHBoxLayout() layoutH1.addWidget(lblLayerPrefix) layoutH1.addWidget(self.leLayerPrefix) self.leOutputPath = QLineEdit() self.tbtnGetPath = QToolButton() layoutH2 = QHBoxLayout() layoutH2.addWidget(self.leOutputPath) layoutH2.addWidget(self.tbtnGetPath) layout = QVBoxLayout() layout.addLayout(layoutH1) layout.addLayout(layoutH2) self.btnRun = QPushButton('&Run') self.pbProcessing = QProgressBar() layout.addWidget(self.btnRun) layout.addWidget(self.pbProcessing) # setting top widget self.resize(200,100) self.setWindowTitle('PS LayerSets Exporter') self.setLayout(layout) def createConnection(self): self.btnRun.clicked.connect(self.processRun) self.tbtnGetPath.clicked.connect(self.setOutputPath) qApp = QApplication(sys.argv) exporter = LayerSetsExporter() exporter.show() qApp.exec_()
Initial URL
Initial Description
with layer set prefix option and custom output path
Initial Title
Export JPEG Files With Each LayerSet with option (Photoshop Python With PyQt)
Initial Tags
python
Initial Language
Python