1
- const { executeAsModal } = require ( "photoshop" ) . core ;
2
- const storage = require ( "uxp" ) . storage ;
3
- const fs = storage . localFileSystem ;
4
- const formats = require ( "uxp" ) . storage . formats ;
1
+ const { executeAsModal } = require ( "photoshop" ) . core
2
+ const storage = require ( "uxp" ) . storage
3
+ const fs = storage . localFileSystem
4
+ const formats = require ( "uxp" ) . storage . formats
5
5
async function exportPngCommand ( ) {
6
- const batchPlay = require ( "photoshop" ) . action . batchPlay ;
6
+ const batchPlay = require ( "photoshop" ) . action . batchPlay
7
7
// const result = await batchPlay { _obj: “exportSelectionAsFileTypePressed”}
8
8
9
9
// const destFolder = (await storage.localFileSystem.getDataFolder()).nativePath;
10
- const storage = require ( "uxp" ) . storage ;
11
- const fs = storage . localFileSystem ;
10
+ const storage = require ( "uxp" ) . storage
11
+ const fs = storage . localFileSystem
12
12
13
- let pluginFolder = await fs . getPluginFolder ( ) ;
13
+ let pluginFolder = await fs . getPluginFolder ( )
14
14
// await fs.getFolder("./init_images")
15
15
let init_images_dir = await pluginFolder . getEntry (
16
16
"./server/python_server/init_images"
17
- ) ;
17
+ )
18
18
19
19
const exportCommand = {
20
20
_obj : "exportSelectionAsFileTypePressed" ,
@@ -26,20 +26,20 @@ async function exportPngCommand() {
26
26
sRGB : true ,
27
27
openWindow : false ,
28
28
_options : { dialogOptions : "dontDisplay" } ,
29
- } ;
29
+ }
30
30
const result = await batchPlay ( [ exportCommand ] , {
31
31
synchronousExecution : true ,
32
32
modalBehavior : "execute" ,
33
- } ) ;
33
+ } )
34
34
35
- return result ;
35
+ return result
36
36
}
37
37
async function exportPng ( ) {
38
- const { executeAsModal } = require ( "photoshop" ) . core ;
38
+ const { executeAsModal } = require ( "photoshop" ) . core
39
39
try {
40
- await executeAsModal ( exportPngCommand ) ;
40
+ await executeAsModal ( exportPngCommand )
41
41
} catch ( e ) {
42
- console . warn ( "exportPng error:" , e ) ;
42
+ console . warn ( "exportPng error:" , e )
43
43
}
44
44
}
45
45
@@ -49,39 +49,39 @@ const readPng = async (image_name) => {
49
49
await executeAsModal (
50
50
async ( control ) => {
51
51
// const tempFolder = await fs.getTemporaryFolder() ;
52
- const pluginFolder = await fs . getPluginFolder ( ) ;
52
+ const pluginFolder = await fs . getPluginFolder ( )
53
53
54
54
let init_images_dir = await pluginFolder . getEntry (
55
55
"./server/python_server/init_images"
56
- ) ;
56
+ )
57
57
// let init_images_dir = await pluginFolder.getEntry(
58
58
// './server/python_server/init_images'
59
59
// )
60
60
const file = await init_images_dir . createFile ( image_name , {
61
61
overwrite : true ,
62
- } ) ;
62
+ } )
63
63
64
- const currentDocument = app . activeDocument ;
64
+ const currentDocument = app . activeDocument
65
65
await currentDocument . saveAs . png (
66
66
file ,
67
67
{
68
68
compression : 6 ,
69
69
} ,
70
70
true
71
- ) ;
71
+ )
72
72
73
73
// const arrayBuffer = await file.read({format: formats.binary}) ;
74
74
// console.log(arrayBuffer, 'arrayBuffer') ;
75
75
} ,
76
76
77
77
{ commandName : "readPng" }
78
- ) ;
78
+ )
79
79
} catch ( e ) {
80
- console . warn ( e ) ;
80
+ console . warn ( e )
81
81
}
82
- } ;
82
+ }
83
83
84
- const psapi = require ( "./psapi" ) ;
84
+ const psapi = require ( "./psapi" )
85
85
async function newExportPng ( layer , image_name ) {
86
86
//store layers we want to export in variables
87
87
// let layerToExports =
@@ -97,24 +97,24 @@ async function newExportPng(layer, image_name) {
97
97
98
98
//create new document
99
99
let exportDoc = await executeAsModal ( async ( ) => {
100
- return await app . documents . add ;
101
- } ) ;
100
+ return await app . documents . add
101
+ } )
102
102
103
103
// for (layer of layersToExport) {
104
104
await executeAsModal ( async ( ) => {
105
- console . log ( layer . id ) ;
106
- const dupLayer = await layer . duplicate ( exportDoc ) ;
107
- await psapi . selectLayers ( [ dupLayer ] ) ;
108
- await psapi . selectLayerChannelCommand ( ) ;
109
- const selection_info = await psapi . getSelectionInfoExe ( ) ;
110
- await exportDoc . crop ( selection_info ) ;
105
+ console . log ( layer . id )
106
+ const dupLayer = await layer . duplicate ( exportDoc )
107
+ await psapi . selectLayers ( [ dupLayer ] )
108
+ await psapi . selectLayerChannelCommand ( )
109
+ const selection_info = await psapi . getSelectionInfoExe ( )
110
+ await exportDoc . crop ( selection_info )
111
111
// export_image_name = `${layer.name}.png`
112
- await readPng ( image_name ) ;
112
+ await readPng ( image_name )
113
113
// await exportDoc.closeWithoutSaving()
114
- } ) ;
114
+ } )
115
115
// }
116
116
} catch ( e ) {
117
- console . warn ( e ) ;
117
+ console . warn ( e )
118
118
}
119
119
}
120
120
@@ -140,17 +140,17 @@ For the save function, if running UXP AP1 version 1 then use "wait" for modalBeh
140
140
If running on UXP API version 2 then use "execute" for modalBahavior, or remove the options and use {} so the options go to default.
141
141
*/
142
142
async function savePNG ( saveDataTemp ) {
143
- const batchPlay = require ( "photoshop" ) . action . batchPlay ;
143
+ const batchPlay = require ( "photoshop" ) . action . batchPlay
144
144
145
145
async function savePNGCommand ( ) {
146
146
var saveFolder =
147
- await require ( "uxp" ) . storage . localFileSystem . getPluginFolder ( ) ;
147
+ await require ( "uxp" ) . storage . localFileSystem . getPluginFolder ( )
148
148
149
149
// Again, my variable here is global and assigned earlier. The value is changed during a batch loop for each file.
150
- var saveFile = await saveFolder . createFile ( "fileName.png" ) ;
150
+ var saveFile = await saveFolder . createFile ( "fileName.png" )
151
151
152
152
const saveData =
153
- await require ( "uxp" ) . storage . localFileSystem . createSessionToken ( saveFile ) ;
153
+ await require ( "uxp" ) . storage . localFileSystem . createSessionToken ( saveFile )
154
154
155
155
const result = await batchPlay (
156
156
[
@@ -190,11 +190,11 @@ async function savePNG(saveDataTemp) {
190
190
synchronousExecution : true ,
191
191
modalBehavior : "execute" ,
192
192
}
193
- ) ;
193
+ )
194
194
}
195
195
await executeAsModal ( async ( ) => {
196
- savePNGCommand ( ) ;
197
- } ) ;
196
+ savePNGCommand ( )
197
+ } )
198
198
}
199
199
200
200
////////////////////End method 3////////////////////////////
@@ -204,4 +204,4 @@ module.exports = {
204
204
readPng,
205
205
savePNG,
206
206
newExportPng,
207
- } ;
207
+ }
0 commit comments