Skip to main content
Known Participant
March 11, 2011
Answered

If Open File Has an Open Clipping Path-Add IPTC Description

  • March 11, 2011
  • 1 reply
  • 847 views

Hello,

Just looking for any pointers. If I have an image open, I want to run a script that will check the top path(or selected path) for any open points. If it is an open path, add "open path" in the IPTC/Description.

I can not figure this out. Any help would be greatly appreciated.

This topic has been closed for replies.
Correct answer Michael_L_Hale

I thought that it was checking all the subpaths in a path. But I only did a quick test with paths made by the line and ellipse shape tool set to paths. If you post a link to a problem file I will see if I can correct the script.


Nevermind with the problem file link. It was a stupid error on my part. The loop that checks the subpaths was only checking

subPathItems[0]( the first subpath instead of subPathItems ( all subpaths ).

var selectedPathIndex = activePathIndex();
if( selectedPathIndex==-1){
     var targetPath = app.activeDocument.pathItems[0];
}else{
     var targetPath = app.activeDocument.pathItems[selectedPathIndex];
}
if(!isPathClosed( targetPath )) app.activeDocument.info.caption = "Open Path";

function isPathClosed( p ){
     for(var s = 0;s<p.subPathItems.length;s++){
          if(!p.subPathItems.closed) return false;
     }
     return true;
};
function activePathIndex(){
     try{
          var ref = new ActionReference();
          ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
          var desc = executeActionGet( ref );
          return  desc.getInteger(charIDToTypeID("TrgP" ));
     }catch(e){}
};

1 reply

Inspiring
March 11, 2011

Something like this...

var selectedPathIndex = activePathIndex();
if( selectedPathIndex==-1){
     var targetPath = app.activeDocument.pathItems[0];
}else{
     var targetPath = app.activeDocument.pathItems[selectedPathIndex];
}
if(!isPathClosed( targetPath )) app.activeDocument.info.caption = "Open Path";

function isPathClosed( p ){
     for(var s = 0;s<p.subPathItems.length;s++){
          if(!p.subPathItems[0].closed) return false;
     }
     return true;
};
function activePathIndex(){
     try{
          var ref = new ActionReference();
          ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
          var desc = executeActionGet( ref );
          return  desc.getInteger(charIDToTypeID("TrgP" ));
     }catch(e){}
};

Known Participant
March 11, 2011

Thanks Michael,

This is very helpful. I wasn't even in the ball park. I marked your response as answered, but I just made a path the shape of a doughnut, one large circle and a smaller circle inside of the large circle. It sees it as an Open Path if the large circle is open. If the large circle is closed and the small circle is open, it does not consider the path to be an Open Path. Basically, it looks like it isn't checking the paths contained within another path

Unfortunately, some of our customers use Quark. We've had many problems with Quark and open paths. If an image with an open path is placed in Quark with the path applied, it can cut huge portions of the image off. I will test this to see if does this when "inner" path objects are left open.

Thanks again Michael. This is a HUGE help!

Danny

Inspiring
March 11, 2011

I thought that it was checking all the subpaths in a path. But I only did a quick test with paths made by the line and ellipse shape tool set to paths. If you post a link to a problem file I will see if I can correct the script.