Export JPEG Files With Each LayerSet with option (Photoshop Python With PyQt)


/ Published in: Python
Save to your folder(s)

with layer set prefix option and custom output path


Copy this code and paste it in your HTML
  1. #-------------------------------------------------------------------------------
  2. # Name: LayerSetsExporter
  3. # Purpose: export files with each layer set
  4. #
  5. # Author: JanusHuang
  6. #
  7. # Created: 24/11/2013
  8. # Copyright: (c) JanusHuang 2013
  9. # Licence: <your licence>
  10. #-------------------------------------------------------------------------------
  11.  
  12. import sys
  13. from PyQt4.QtGui import *
  14. import comtypes.client
  15.  
  16. class LayerSetsExporter(QWidget):
  17.  
  18. def __init__(self, parent = None):
  19. super(LayerSetsExporter, self).__init__(parent)
  20. self.outputPath = ''
  21. self.createLayout()
  22. self.createConnection()
  23.  
  24. def setLayerSetsVisible(self, layerSets, state):
  25. for layerSet in layerSets:
  26. layerSet.visible = False
  27.  
  28. def saveLayerSetsVisible(self, layerSets):
  29. self.origLayerSetsVisible = []
  30. for layerSet in layerSets:
  31. self.origLayerSetsVisible.append([layerSet, layerSet.visible])
  32.  
  33. def resetLayerSetsVisible(self):
  34. for (layerSet, visible) in self.origLayerSetsVisible:
  35. layerSet.visible = visible
  36.  
  37. def getExportFileName(self, layerSet):
  38. newStr = layerSet.name.replace(self.leLayerPrefix.text(), '')
  39. return newStr
  40.  
  41. def setOutputPath(self):
  42. self.outputPath = str(QFileDialog.getExistingDirectory(self, "Select Directory")) + '\\'
  43. self.leOutputPath.setText(self.outputPath)
  44.  
  45. def processRun(self):
  46. app = comtypes.client.CreateObject('Photoshop.Application')
  47. doc = app.activeDocument
  48. if self.leOutputPath.text() == '':
  49. self.outputPath = doc.path
  50. self.leOutputPath.setText(self.outputPath)
  51.  
  52. optionJpg = comtypes.client.CreateObject('Photoshop.JPEGSaveOptions')
  53. optionJpg.quality = 8
  54.  
  55. count = 1
  56. layerSets = doc.layerSets
  57. #self.pbProcessing.setMaximum(layerSets.length)
  58. self.saveLayerSetsVisible(layerSets)
  59. for layerSet in layerSets:
  60. if self.leLayerPrefix.text() in layerSet.name:
  61. self.setLayerSetsVisible(layerSets, False)
  62. layerSet.visible = True
  63. doc.saveAs(self.outputPath + self.getExportFileName(layerSet) + '.jpg', optionJpg, True)
  64. self.pbProcessing.setValue(count)
  65. count += 1
  66. self.resetLayerSetsVisible()
  67. self.pbProcessing.reset()
  68.  
  69. def createLayout(self):
  70. lblLayerPrefix = QLabel('Layer Prefix :')
  71. self.leLayerPrefix = QLineEdit('ept_')
  72. layoutH1 = QHBoxLayout()
  73. layoutH1.addWidget(lblLayerPrefix)
  74. layoutH1.addWidget(self.leLayerPrefix)
  75.  
  76. self.leOutputPath = QLineEdit()
  77. self.tbtnGetPath = QToolButton()
  78. layoutH2 = QHBoxLayout()
  79. layoutH2.addWidget(self.leOutputPath)
  80. layoutH2.addWidget(self.tbtnGetPath)
  81.  
  82. layout = QVBoxLayout()
  83. layout.addLayout(layoutH1)
  84. layout.addLayout(layoutH2)
  85. self.btnRun = QPushButton('&Run')
  86. self.pbProcessing = QProgressBar()
  87. layout.addWidget(self.btnRun)
  88. layout.addWidget(self.pbProcessing)
  89.  
  90. # setting top widget
  91. self.resize(200,100)
  92. self.setWindowTitle('PS LayerSets Exporter')
  93. self.setLayout(layout)
  94.  
  95. def createConnection(self):
  96. self.btnRun.clicked.connect(self.processRun)
  97. self.tbtnGetPath.clicked.connect(self.setOutputPath)
  98.  
  99. qApp = QApplication(sys.argv)
  100.  
  101. exporter = LayerSetsExporter()
  102. exporter.show()
  103.  
  104. qApp.exec_()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.