Copy link to clipboard
Copied
I am trying to stop a script if no layer is selected.
I am finding it wierd why this command returns the first layer even if nothing is selected
alert (app.activeDocument.activeLayer.name);
I tried doing try catch instead of throwing an error when no layer is selected. But that also didn't work
Folks, I am new here. Please guide to help me understand better
Copy link to clipboard
Copied
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayers'));
r.putEnumerated(s2t("document"), s2t("ordinal"), s2t("targetEnum"));
if (!executeActionGet(r).getList(p).count) alert('no layers selected')
Copy link to clipboard
Copied
@defaultseiiesa394z4 – It's a well-known bug when using DOM code, as the excellent script from @jazz-y shows, it takes the more esoteric AM code to overcome the issue.
Copy link to clipboard
Copied
So since you asked about stopping the script. You can use jazz-y's script. Create a variable called run and set it to true. Create an if statement for all your routine code and have the condition be the run variable. Then in jazz-y's script, change the run variable to false, if no layer is select. Tje script will then bypass all your code in the if statement and end.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@defaultseiiesa394z4 - So how did you go with the code and suggestions?