Skip to main content
Inspiring
February 7, 2025
Answered

check if the path exists

  • February 7, 2025
  • 2 replies
  • 416 views

I want to check if the path exists
I need this script in javascript no uxp
this is what I tried but it doesn't work.

try { app.activeDocument.paths["TEST"]; 
    alert("ok"); 
    
    } catch(e) { 
    alert("ko"); 
        
        }
Correct answer c.pfaffenbichler

 

If it is about a path with a specific name try 

try {var thePath = activeDocument.pathItems.getByName("TEST");
    alert ("ok")}
catch (e) {alert ("ko")}

 

2 replies

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
February 7, 2025

 

If it is about a path with a specific name try 

try {var thePath = activeDocument.pathItems.getByName("TEST");
    alert ("ok")}
catch (e) {alert ("ko")}

 

Inspiring
February 7, 2025

THANK YOU

Stephen Marsh
Community Expert
Community Expert
February 7, 2025

@Ciccillotto 

 

You need to check the pathItems collection, here it is in a conditional:

 

if (app.activeDocument.pathItems.length) {
    alert("Paths exist...");
} else {
    alert("No paths exist...");
}

 

With modified code, you can also check explicitly for various path kinds such as "PathKind.WORKPATH" or "PathKind.NORMALPATH" or a "PathKind.CLIPPINGPATH".

Inspiring
February 7, 2025

THANK YOU

Stephen Marsh
Community Expert
Community Expert
February 7, 2025
quote

THANK YOU


By @Ciccillotto

 

You're welcome, I only answered for a generic test of any path as I didn't read your code properly (when I saw paths instead of pathItems I stopped reading, sorry). The post from @c.pfaffenbichler was better as it was explicitly for a named path.