Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Calling External API

Community Beginner ,
Jul 20, 2023 Jul 20, 2023

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();
}
TOPICS
Scripting

Views

483
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jul 20, 2023 Jul 20, 2023

Copy link to clipboard

Copied

Not readily possible by just using Extendscript. However there are some ways you could try.

  • Create a CEP extension and make the call using the JS part and do the Illustrator DOM manipulation using the JSX script. https://github.com/Adobe-CEP/CEP-Resources
  • Extendscript has a socket object, you will need to use it and program it to handle HTTP requests. A complex job.
  • Create a C++ library which provide methods exposed to extendscript which can make the HTTP call.
  • Execute a batch/command file from jsx and make the call from the batch/command file. The result transfer may be done via something like a text file

-Manan

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

Is this possible with other scripting languages like VB script and Apple script? 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2023 Jul 21, 2023

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

Back in June, Kris Coppieters made an update to his project along bullet 3:

https://coppieters.nz/?p=720

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 21, 2023 Jul 21, 2023

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines