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

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

Advocate ,
Apr 06, 2021 Apr 06, 2021

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
1.2K
Translate
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

 

Translate
Participant ,
Apr 06, 2021 Apr 06, 2021

Have you tryed to use a try/catch statement?

 

 

Translate
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

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.

Translate
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

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

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

 

Translate
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
LATEST

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

Translate
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