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

javascript doScript error

Community Beginner ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Good morning! I am hoping that someone can help me.

 

I am struggling with running an action via JavaScript. I am using CC2021 on Windows 10.

 

It should be simple: app.doScript(Action Set, Action);

 

What I'm trying to accomplish is to export a PNG with the same results as if I'd used "File" ==> "Export" ==> "Export As...".  Normally my solution would be via an Action as I can record my settings.

 

However, I need to develop a targeted path for the final PNG.

 

In a perfect world, I could use a JavaScript "export as png" type function, but neither JavaScript's png8 or png24 method quality is as good as a 300 ppi "Export As..." export option.

 

I stumbled on another suggestion on the message boards using the "ImageCapture" method:

 

function exportFileToPNG (dest) {
    if (app.documents.length > 0) {
        var options = new ImageCaptureOptions();
        options.artBoardClipping = true;
        options.resolution = 400;
        options.antiAliasing = true;
        options.matte = false;
        options.horizontalScale = 100;
        options.verticalScale = 100;
        options.transparency = true;

        var fileSpec = new File(dest);

        app.activeDocument.imageCapture(fileSpec, undefined, options);
    }
}

 

This method provides better results than the png8 & png24 methods, but is still not as good as the "Export As..." method and the file size is much larger.

 

Last year I stumbled upon Silly-V's genius solution to create Dynamic Actions and have used it successfully.  That is what I'm trying to do now. Everything works, except the "doScript" part. Illustrator says "Play Action" is not available.

 

I've even tried a simple javascript to call ANY action, including the default actions. The result is the same every time - "The object 'Play Action' is not currently available". 

 

It seems that "app.doScript(ActionSet, Action)" nor "app.doScript(Action, ActionSet)" works for me.

 

Has something changed for CC2021? Or have the "doScript" parameters changed?

 

Here is the simple code which refuses to run:

 

#target illustrator

app.doScript("TEMP Actions", "GO");

 

That's it! The Action Set is called "TEMP Actions" and the Action is "GO". I've tried changing the order and it fails. Then I tried some of the default actions and it still fails.

 

Funny thing is that if I cancel at the error level instead of "Continue", the dynamic action added during the JavaScript run will play correctly if I click on it. 

 

I've tried having JavaScript build a VBScript to run the Action:

 

var vbs = 'Set appRef = CreateObject("Illustrator.Application")\r';
      vbs += 'appRef.DoScript "GO", "TEMP Actions"\r';
      vbs += 'WHILE(appRef.ActionIsRunning)\r';
      vbs += '\tWScript.sleep 1000\r';
      vbs += 'WEND\r';
app.doScript(vbs, ScriptLanguage.VISUAL_BASIC, undefined, UndoModes.FAST_ENTIRE_SCRIPT);

 

This results in a "ScriptLanguage is undefined" error. 

 

I apologize if  this is confusing. I would really appreciate any help that you could provide.

 

Thank you!

TOPICS
Import and export , Print and publish , Scripting

Views

648

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

correct answers 1 Correct answer

Community Beginner , Nov 09, 2020 Nov 09, 2020

I'm gonna cry!

 

After giving you all that information and telling you everyting I've tried, INCLUDING switching the order in the doScript command, I tried one more time with "doScript(Action, ActionSet)" and it worked!

 

Please forgive me for wasting your time!

 

But thanks for waving your magic wand!!

 

Thanks again!

 

 

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Hi,

Did you try to record the same action and save it with the same file name and execute it.

Best regards

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
Community Beginner ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Hi! Thank you for your quick reply! Yes, I've tried that too. As I said earlier, the action plays correctly from the Actions menu, but calling it from JavaScript is where it is breaking down. It is supposed to be simple: doScript(Action Set, Action).

 

I did see one post that had a "false" in the third space, which would give me "doScript(Action Set, Action, false)" which changes nothing.

 

Thank you again for your help!

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
Community Beginner ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

Sorry, I meant "Yes, I just tried that at your suggestion and even though the new Action works, I can't call it via JavaScript". Thank you for the suggestion!

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
Community Beginner ,
Nov 09, 2020 Nov 09, 2020

Copy link to clipboard

Copied

LATEST

I'm gonna cry!

 

After giving you all that information and telling you everyting I've tried, INCLUDING switching the order in the doScript command, I tried one more time with "doScript(Action, ActionSet)" and it worked!

 

Please forgive me for wasting your time!

 

But thanks for waving your magic wand!!

 

Thanks again!

 

 

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