Hi,
I work a lot with Photoshop and I decided to jump into the “fun” world of coding to try and automate some of the work I do.
Now please bear with me as I’ve never really coded anything in my life.
To get started I created my first plugin using the starting template, which is a simple button to create a new document with a new text layer saying “Hello Photoshop!”
However, when I click the button nothing happens. I’m sure I’m doing something fundamentally wrong but as I’m a beginner I’m struggling to figure out what exactly.
Any help would be great.
Here’s the code
const { entrypoints } = require("uxp");
showAlert = () => {
alert("This is an alert message");
}
entrypoints.setup({
commands: {
showAlert,
},
panels: {
vanilla: {
show(node ) {
}
}
}
});
function createNewDocument() {
const app = require('photoshop').app;
document = app.documents.add(50, 50, 72, "helloPhotoshop");
let layer = document.artLayers.add()
layer.kind = LayerKind.TEXT;
layer.textItem.contents = "Hello Photoshop!";
layer.textItem.size = 50;
}
document.getElementById("btnNewdocument").addEventListener("click", createNewDocument);
<!DOCTYPE html>
<html>
<head>
<script src="main.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<sp-heading>Create New Doc</sp-heading>
<footer>
<sp-button id="btnNewdocument">New</sp-button>
</footer>
</body>
</html>