-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
53 lines (44 loc) · 1.71 KB
/
main.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
/*
* Sample plugin scaffolding for Adobe XD.
*
* Visit http://adobexdplatform.com/ for API docs and more sample code.
*/
const { Text, Color } = require("scenegraph");
const commands = require("commands");
const { alert, error } = require("./lib/dialogs.js");
function colordetails(selection, documentRoot) {
if(selection.items.length !== 0){
try{
selection.items.forEach(item => {
const node = item;
let x = node.globalBounds.x;
let y = node.globalBounds.y;
const hex = new Text();
hex.text = String(node.fill.toHex(true))
hex.fill = new Color("#000000")
hex.fontSize=node.globalBounds.height / 2;
hex.moveInParentCoordinates(x+node.globalBounds.width,y+node.globalBounds.height)
console.log(hex.globalBounds);
const rgb = new Text();
rgb.text = "rgb(" + String(node.fill.r) + ","+ String(node.fill.g) + "," + + String(node.fill.b) + ")";
rgb.fill = new Color("#000000")
rgb.fontSize=node.globalBounds.height / 2;
rgb.moveInParentCoordinates(x+node.globalBounds.width,y+(node.globalBounds.height/2))
console.log(rgb.globalBounds);
documentRoot.addChild(hex,1);
documentRoot.addChild(rgb,1);
});
}
catch{
error("Make sure you have selected one or more rectangles that have a fill")
}
}
else{
alert("Please select one or more rectangles filled with a color");
}
}
module.exports = {
commands: {
colordetails
}
};