Created
October 15, 2018 01:30
-
-
Save peterflynn/e6e7101fac6ad48087285e772e52b96a to your computer and use it in GitHub Desktop.
XD Plugins - part 2 finished code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Sample plugin code for Adobe XD. | |
* | |
* Visit http://adobexdplatform.com/ for API docs and more sample code. | |
*/ | |
var {Rectangle, Color} = require("scenegraph"); | |
function createRectangle(selection) { | |
var textNode = selection.items[0]; | |
var bounds = textNode.boundsInParent; | |
console.log(bounds); | |
const padding = 10; | |
var shape = new Rectangle(); | |
shape.width = bounds.width + 2*padding; | |
shape.height = bounds.height + 2*padding; | |
shape.stroke = new Color("blue"); | |
selection.insertionParent.addChild(shape); | |
shape.placeInParentCoordinates( | |
{x: 0, y: 0}, | |
{x: bounds.x - padding, y: bounds.y - padding} | |
); | |
} | |
module.exports = { | |
commands: { | |
myPluginCommand: createRectangle | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Sample Plugin: Create Button Frame", | |
"id": "YOUR_ID_HERE", | |
"version": "1.0.0", | |
"description": "Sample plugin code for Adobe XD. Creates a rectangle around the selected text, with fixed padding.", | |
"host": { | |
"app": "XD", | |
"minVersion": "13.0.0" | |
}, | |
"uiEntryPoints": [ | |
{ | |
"type": "menu", | |
"label": "Create Button Frame", | |
"commandId": "myPluginCommand" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment