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

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

575

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

Advocate , Apr 06, 2021 Apr 06, 2021

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

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

 

Votes

Translate

Translate
Participant ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Have you tryed to use a try/catch statement?

 

 

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
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.

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
Advocate ,
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

 

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
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.

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