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.
Copy link to clipboard
Copied
try {
app.doScript ('actionName', 'setName');
}
catch (e) {
alert ("does not exists")
}
Have fun
Copy link to clipboard
Copied
Would this not trigger also when actions naturally produce some error?
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
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.
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:
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();