Copy link to clipboard
Copied
Is it possible to call External API in adobe illustrator scripting ?
app.preferences.setBooleanPreference("ShowExternalJSXWarning", false);
run();
function run() {
// Creating Our XMLHttpRequest object
const xhr = new XMLHttpRequest();
// // Making our connection
var url = "https://jsonplaceholder.typicode.com/todos/1";
xhr.open("GET", url, true);
// // function execute after request is successful
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
}
// // Sending our request
xhr.send();
// Set the path to your AI file
var filePath = "C://Projects//IllustratorPacking//Labels//Source/AAB.ai";
// Set the text to find and replace
var searchText = "EMAIL";
var replaceText = this.responseText.title;
// Open the AI file
var doc = app.open(new File(filePath));
// Iterate through all text items in the document
for (var i = 0; i < doc.textFrames.length; i++) {
var textFrame = doc.textFrames[i];
// Check if the text contains the search text
if (textFrame.contents.indexOf(searchText) !== -1) {
// Replace the text
textFrame.contents = textFrame.contents.replace(searchText, replaceText);
}
}
// Save and close the modified AI file
doc.save();
doc.close();
}
Copy link to clipboard
Copied
Not readily possible by just using Extendscript. However there are some ways you could try.
-Manan
Copy link to clipboard
Copied
Is this possible with other scripting languages like VB script and Apple script?
Copy link to clipboard
Copied
Yes it is, as mentioned in my last point. Any executable file can be executed using the execute method of the File object. So write your code in the executable file like a .command file on a MAC and call the execute method on it from Extendscript. The only thing for you to figure out is how to exchange the data back and forth
-Manan
Copy link to clipboard
Copied
Back in June, Kris Coppieters made an update to his project along bullet 3:
Copy link to clipboard
Copied
I know about that, in the past I created the same utility myself. I did not provide the link for it as I was not sure how Kris was licensing it.
-Manan