Advertisement
Baoulettes

cat_label_auto

Jan 31st, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. // Exports a saved multi-layered file as a .png in the same directory.
  2.  
  3. function SaveCategories_png(){
  4. // Confirm the document has already been saved and so has a path to use
  5. try {
  6. app.activeDocument.save()
  7. } catch(e) {
  8. alert("Could not export PNG as the document is not saved.\nPlease save and try again.")
  9. return
  10. }
  11. // Categories list :
  12. var Categories = new Array(
  13. '-',
  14. 'Fusion',
  15. 'Dragon\rmaléfique',
  16. 'Tenkaichi\rBudokai',
  17. 'Fille pleine\rde vie',
  18. 'Saiyan de\rsang-mêlé',
  19. 'Survie de\rl\'Univers',
  20. 'Ressuscité',
  21. 'Divin',
  22. 'Saga de Boo',
  23. 'Potalas',
  24. 'Guerrier\rinférieur',
  25. 'Super Saiyan 3',
  26. 'Forme géante',
  27. 'Saga de Namek',
  28. 'Commando\rGinyu',
  29. 'Boss des films',
  30. 'Saiyan pur',
  31. 'Namek',
  32. 'Saga du futur',
  33. 'Puissance\rmaximale',
  34. 'Cyborg',
  35. 'Représentants de\rl\'Univers 7',
  36. 'Transformation\rfortifiante',
  37. 'Lignée diabolique',
  38. 'Chercheurs de\rboules de cristal',
  39. 'Voyageur\rdu temps',
  40. 'Univers 6',
  41. 'Forces jointes',
  42. 'Héros des films',
  43. 'Famille de\rGoku',
  44. 'Famille de\rVegeta',
  45. 'Vie artificielle',
  46. 'Enfant',
  47. 'Arc enfant',
  48. 'Lien de\rfratrie',
  49. 'Super Saiyan',
  50. 'Digne rival',
  51. 'Cyborg -\rSaga de Cell',
  52. 'Kamehameha',
  53. 'Lien maître\ret disciple',
  54. 'Conquérant',
  55. 'Dragon Ball\rHeroes',
  56. 'Cible:\rSon Goku',
  57. 'Guerrier de\rl\'au-delà',
  58. 'Super Saiyan 2',
  59. 'Dernier atout'
  60. );
  61. for (id = 0; id < Categories.length ;) {
  62. //for (id = 0; id < 4 ;) {
  63. var currentname = Categories[id];
  64. var currentid = id;
  65. if (currentid <= 9) {
  66. var currentid = '000'+id;
  67. } else if (currentid <= 99) {
  68. var currentid = '00'+id;
  69. } else if (currentid <= 999) {
  70. var currentid = '00'+id;
  71. }
  72.  
  73.  
  74. // Store the active doc handle in variable
  75. var originalDoc = app.activeDocument
  76. if (currentname.indexOf("\r") != -1) {
  77. changeTextLayerContent(originalDoc, '1Line', '');
  78. changeTextLayerContent(originalDoc, '2Line', Categories[id]);
  79. } else {
  80. changeTextLayerContent(originalDoc, '1Line', Categories[id]);
  81. changeTextLayerContent(originalDoc, '2Line', '');
  82. }
  83.  
  84. // Check there is at least 1 visible layer.
  85. var foundVisible = false
  86. for (i = 0; i < originalDoc.layers.length; i++) {
  87. if (originalDoc.layers[i].visible) {
  88. foundVisible = true
  89. break
  90. }
  91. }
  92.  
  93. if (!foundVisible){
  94. alert("No visible layers found. PNG export failed.")
  95. return
  96. }
  97.  
  98. // Duplicate. We'll save the duplicate as a .png and close it.
  99. var newDoc = originalDoc.duplicate()
  100. // Photoshop must have a visible layer selected to merge visible layers, so we ensure there is one selected.
  101. var dummyVisibleLayer = newDoc.artLayers.add();
  102. newDoc.activeLayer = dummyVisibleLayer
  103.  
  104. // Merge the layers.
  105. newDoc.mergeVisibleLayers()
  106.  
  107. // Remove all empty layers.
  108. for (i = newDoc.layers.length-1; i >=0; i--){
  109. if (!newDoc.layers[i].visible){
  110. newDoc.layers[i].remove()
  111. }
  112. }
  113. pngOptions = new PNGSaveOptions()
  114. pngOptions.compression = 0
  115. pngOptions.interlaced = false
  116. savePath = File(originalDoc.path + '/'+'Label_'+currentid+'.png');
  117. newDoc.saveAs(savePath, pngOptions, false, Extension.LOWERCASE)
  118. newDoc.close()
  119. app.activeDocument=originalDoc
  120. id++
  121. }
  122. }
  123. function changeTextLayerContent(doc, layerName, newTextString) {
  124. for (var i = 0, max = doc.layers.length; i < max; i++) {
  125. var layerRef = doc.layers[i];
  126. if (layerRef.typename === "ArtLayer") {
  127. if (layerRef.name === layerName && layerRef.kind === LayerKind.TEXT) {
  128. layerRef.textItem.contents = newTextString;
  129. }
  130. } else {
  131. changeTextLayerContent(layerRef, layerName, newTextString);
  132. }
  133. }
  134. }
  135. SaveCategories_png()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement