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

Read arguments from cmd line for Illustrator script

New Here ,
Jul 15, 2024 Jul 15, 2024

Copy link to clipboard

Copied

Hello there, 

I'm trying to execute script via cmd terminal & in script I need to read and write file to certain dir basically create a copy of exising work, while checking arguments length is returning 0, as an example here is my script which reads AI file from my local and create an svg write it to destination path, but still getting arguments undefined, Can someone guide me how to get value in scripts from passed string in cmd

Example  Script

 

if (arguments.length < 2) {
    alert("Insufficient arguments provided. Expected source and destination file paths.");
    quit();
}


try {
    var sourceFilePath = arguments[0];
    var destFilePath = arguments[1];
    
    var sourceFile = File(sourceFilePath);
    var destFile = File(destFilePath);
   
    $.writeln("Source file: " + sourceFile.fsName);
    $.writeln("Destination file: " + destFile.fsName);

    if (sourceFile.exists) {
        var doc = app.open(sourceFile);
        var options = new ExportOptionsSVG();
        var type = ExportType.SVG;
        options.embedRasterImages = true;
        doc.exportFile(destFile, type, options);
        doc.close(SaveOptions.DONOTSAVECHANGES);
        $.writeln("Export successful!");
    } else {
        $.writeln("Source file does not exist.");
    }
} catch (e) {
    $.writeln("Error: " + e.message);
}

 


Terminal

 

C:\Users\Desktop\ProjectScript>"C:\\Program Files\\Adobe\\Adobe Illustrator CS6 (64 Bit)\\Support Files\\Contents\\Windows\\Illustrator.exe" -r "C:\\Users\\Desktop\\ProjectScript\\src\\Test.jsx" "C:\\Users\\Desktop\\ProjectScript\\assets\\AI_SAMPLE.ai" "C:\\Users\\Desktop\\ProjectScript\\assets\\converted\\SVG_SAMPLE.svg"

 



Thanks 


 

TOPICS
Experiment , How-to , Import and export , Scripting , Type

Views

132

Translate

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
Enthusiast ,
Jul 19, 2024 Jul 19, 2024

Copy link to clipboard

Copied

LATEST

arguments does not refer to command line, it's specifically referring only to in-scope parameters of the function it's scoped within. In other words, it doesn't work like that, it only refers to what exists inside Javascript and the Javascript file you're running:

 

 

 

function helloWorld() {
  for (param of arguments) alert(param);
}

helloWorld("a", "b", "c");
// "a"
// 
// "b"
// 
// "c"

alert(arguments) // Always "Undefined" or length of 0, it doesn't exist in root/global scope in any meaningful way

 

 

 

You could write a batch file which would write these params to a temp file on Desktop then launch the extension and run the script which reads then parses that temp file to get the same result or a bin command for NodeJS to do something similar but as it stands the default behavior of shell has no bearing or relation to the scripting environment within the app.

Votes

Translate

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