-
Notifications
You must be signed in to change notification settings - Fork 511
/
helper.js
120 lines (108 loc) · 3.05 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const { unselectActiveLayers } = require('./psapi')
const app = window.require('photoshop').app
function getActiveLayer() {
let activeLayers = app.activeDocument.activeLayers
// console.dir(getSize())
for (const layer of activeLayers) {
console.dir({ layer })
const name = layer.name
console.dir({ name })
let layer_size = getLayerSize(layer)
console.dir({ layer_size })
}
return activeLayers[0]
}
function getSize() {
let doc = app.activeDocument
return { height: doc.height, width: doc.width }
}
const { batchPlay } = require('photoshop').action
const { executeAsModal } = require('photoshop').core
async function reselectBatchPlay(selectionInfo) {
const result = await batchPlay(
[
{
_obj: 'set',
_target: [
{
_ref: 'channel',
_property: 'selection',
},
],
to: {
_obj: 'rectangle',
top: {
_unit: 'pixelsUnit',
_value: selectionInfo.top,
},
left: {
_unit: 'pixelsUnit',
_value: selectionInfo.left,
},
bottom: {
_unit: 'pixelsUnit',
_value: selectionInfo.bottom,
},
right: {
_unit: 'pixelsUnit',
_value: selectionInfo.right,
},
},
_options: {
dialogOptions: 'dontDisplay',
},
},
],
{
synchronousExecution: true,
modalBehavior: 'execute',
}
)
}
async function reselect(selectionInfo) {
await executeAsModal(
async () => {
reselectBatchPlay(selectionInfo)
},
{ commandName: 'reselect' }
)
}
//unselect the rectangular marquee selection area
async function unSelect() {
const batchPlay = require('photoshop').action.batchPlay
const result = await batchPlay(
[
{
_obj: 'set',
_target: [
{
_ref: 'channel',
_property: 'selection',
},
],
to: {
_enum: 'ordinal',
_value: 'none',
},
_options: {
dialogOptions: 'dontDisplay',
},
},
],
{
synchronousExecution: true,
modalBehavior: 'execute',
}
)
return result
}
/**
* Convert 1d index to 2d array
* @param {number} index sequential index
* @param {number} width width of 2d array
* @returns {number[]} [x,y]
*/
function indexToXY(index, width) {
return [index % width, Math.floor(index / width)]
}
module.exports = {}