Highlighted

How can detect a Action exist or not?

Enthusiast ,
Jul 04, 2019

Copy link to clipboard

Copied

I want check  a Action exist or not:

If Action not exist , i will show a message to request import action.

How can detect a Action exist or not?

Thank you.

TOPICS
Scripting

Views

394

Likes

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

How can detect a Action exist or not?

Enthusiast ,
Jul 04, 2019

Copy link to clipboard

Copied

I want check  a Action exist or not:

If Action not exist , i will show a message to request import action.

How can detect a Action exist or not?

Thank you.

TOPICS
Scripting

Views

395

Likes

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
Jul 04, 2019 0
Most Valuable Participant ,
Jul 05, 2019

Copy link to clipboard

Copied

try {

    app.doScript ('actionName', 'setName');

    }

catch (e) {

    alert ("does not exists")

    }

Have fun

Likes

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
Reply
Loading...
Jul 05, 2019 0
Adobe Community Professional ,
Jul 07, 2019

Copy link to clipboard

Copied

Would this not trigger also when actions naturally produce some error?

Likes

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
Reply
Loading...
Jul 07, 2019 0
Enthusiast ,
Jul 07, 2019

Copy link to clipboard

Copied

       I using a COM of Illustrator, if call a action not exist , not will show dialog on Illustrator App , it will hang app and can't catch error.

      Dim app     

        app = CreateObject("Illustrator.Application.CC.2017")    

        Dim doc = app.ActiveDocument

        Try

            app.DoScript("test", "Set_Action3")

        Catch ex As Exception

        End Try

Likes

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
Reply
Loading...
Jul 07, 2019 1
Adobe Community Professional ,
Jul 08, 2019

Copy link to clipboard

Copied

Indeed, I have tested this and when an action produces a regular action error then it does not go to the catch block. So it all works like you guys say.

Likes

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
Reply
Loading...
Jul 08, 2019 0
Engaged ,
Aug 10, 2020

Copy link to clipboard

Copied

Hey @pixxxel_schubser, when I try this it doesn't run the alert in the catch block.

 

alert(checkIfActionExists())

function checkIfActionExists() {
  try {
    app.doScript("actionName", "setName");
    return true;
  } catch (e) {
    alert("does not exists");
    return false;
  }
}

 

It always shows the dialog box saying "The object 'Play action' is not currently available", prompts me to press continue, then always returns true. Is there any way to get this as a boolean instead?

 

My use case is this -- I have a list of actions I want to load via scripting. These are too heavy to load and unload every time because they cause a delay, but there are too many to conveniently split into single action/sets for load/unload per use to fix this. I want to load all only if they don't previously exist:

 

  1. User hits a button
  2. Script checks if Actions exist -- I'd like/need this as a boolean without a dialog if possible
  3. If Actions do not exist, load them
  4. Script executes particular Action

Likes

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
Reply
Loading...
Aug 10, 2020 0
Adobe Community Professional ,
Aug 11, 2020

Copy link to clipboard

Copied

I've been researching this issue for years without success, I mean, not continuously but you get the idea.

 

Today I gave it another shot with a fresh set of new ideas...sadly they all failed again. But then it downed on me, why not try a little social engineering?

 

so this is the concept, check for something the Action is expected to do, if it doesn't do it, then it is not loaded, that simple.

 

on this example, my Action swaps fill/stroke of a selected object so I'm checking fill color black property

 

// doesActionExist.jsx
// carlos canto
// https://community.adobe.com/t5/illustrator/how-can-detect-a-action-exist-or-not/td-p/10499224?page=1

function main() {
    app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; // this prevents the "The Object Play Action is not currently available" message from showing
    var actionName = 'swapColor';
    var actionSet = 'myActions';
    
    // check for something you action is expected to change
    var beforeAction = selection[0].fillColor.black;
    
    app.doScript(actionName, actionSet);

    // check again if your action made such change
    var afterAction = selection[0].fillColor.black;

    if (beforeAction == afterAction) {
        alert(actionName + ' Action does not exist');
    }
    else {
        alert(actionName + ' Action was executed');
    }

    app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;
}

main();

 

Likes

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
Reply
Loading...
Aug 11, 2020 3