Highlighted

Check if path name exists

Explorer ,
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...
}
Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

189

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

Check if path name exists

Explorer ,
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...
}
Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

190

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
Jun 02, 2020 0
Adobe Community Professional ,
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

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
Reply
Loading...
Jun 02, 2020 1
kb3 LATEST
Explorer ,
Jun 02, 2020

Copy link to clipboard

Copied

It works 🙂

Thank you!

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
Reply
Loading...
Jun 02, 2020 0