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

Check if path name exists

Explorer ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

Hi, I hope, that someone can help. I want to check if the pathname exists. If YES -do this, else - do that.

Something in this direction.
MyPath = app.activeDocument.pathItems.getByName("name");
if (MyPath.name exists) {
Do this ...
}
else {
Do that...
}
TOPICS
Scripting

Views

413

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

Community Expert , Jun 02, 2020 Jun 02, 2020

I think if the path does not exist the code will crash while trying to use the getByName method. So you can use try catch block to solve your problem

var exists = false
try{
  var MyPath = app.activeDocument.pathItems.getByName("name");
  exists = true
}
catch(e)
{
}
if (exists) {
Do this ...
}
else {
Do that...
}

-Manan

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

I think if the path does not exist the code will crash while trying to use the getByName method. So you can use try catch block to solve your problem

var exists = false
try{
  var MyPath = app.activeDocument.pathItems.getByName("name");
  exists = true
}
catch(e)
{
}
if (exists) {
Do this ...
}
else {
Do that...
}

-Manan

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
Explorer ,
Jun 02, 2020 Jun 02, 2020

Copy link to clipboard

Copied

LATEST

It works 🙂

Thank you!

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