Copy link to clipboard
Copied
Hi I hope that you're well, I'm new to CEP in Indesign (and in general) I am slightly confused to where i put the latter part of my script. I have put this into the bottom of my index.html file, but I'm not sure if this is the right place. At the moment creating an instance of CSInterface is working and I get the message it has been logged (I have done this for debugging purposes) and when the button is clicked I get the messgae it worked, however, the openDocument() function doesn't run. And when I write it through the console I get the error app not defined. I have a feeling that I need to put the last part of the script into a .jsx file but I am not sure where to put it or how to reference it.
Any help would be much appreciated!
Cheers
<script type="text/javascript">
/* 1) Create an instance of CSInterface. */
var csInterface = new CSInterface();
console.log(csInterface)
console.log("cs interface has been logged!")
/* 2) Make a reference to your HTML button and add a click handler. */
var openButton = document.querySelector("#open-button");
window.onload=function(){
openButton.addEventListener("click", openDoc);
}
/* 3) Write a helper function to pass instructions to the ExtendScript side. */
function openDoc() {
console.log("It Worked")
csInterface.evalScript("openDocument()");
}
function openDocument(){
var myDocument = app.documents.add();
var myTextFrame = myDocument.pages.item(0).textFrames.add();
myTextFrame.geometricBounds = ["6p", "6p", "24p", "24p"];
myTextFrame.contents = "Hello World!";
//console.log("hello");
}
</script>
Copy link to clipboard
Copied
Are you writing a script or, like, a whole panel?
Have you seen these articles?