Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Extendscript: how do I verify that an object is valid?

Enthusiast ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I've got an object that stores references to comps and layers, and I am trying to validate the object before attempting to access those objects. How can I test whether these comps and layers are valid (i.e. have not been deleted)? Even after they have been deleted they still register as objects, so conventional tests for the object's existence don't work, but any attempt to access them throws an "Object is invalid" error, so I can't test the object's structure for validity.

TOPICS
Scripting

Views

133

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Apr 06, 2021 Apr 06, 2021
There's a method for that: isValid(obj); https://ae-scripting.docsforadobe.dev/general/globals/#isvalid

Likes

Translate

Translate
Participant ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Have you tryed to use a try/catch statement?

 

 

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
community guidelines
Enthusiast ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I experimented with it a bit, but I'm not quite sure how to construct a function to which I can pass a potentially invalid object to test. The script simply stops execution when I try to do so.

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
community guidelines
Adobe Community Professional ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

There's a method for that: isValid(obj);

https://ae-scripting.docsforadobe.dev/general/globals/#isvalid

 

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
community guidelines
Enthusiast ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

Fantastic. I'm not sure how I missed it when searching the docs, but this is a lifesaver.

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
community guidelines