Read filename for path name and copy path from 2nd document

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Limey

Read filename for path name and copy path from 2nd document

Post by Limey »

Hi folks,
We have a major project in the works and I have run into a challenge. We have web generated custom colored patterns that need clipping but the files generated do not have clipping paths. We will have the paths stored in a separate document that will act as an archive of paths for all patterns. The archive document for the paths will be the same size as the pattern documents. The pattern file name will contain the pattern number between the first 2 hyphens. I would like to say that it would be a set number of characters but it may include a version suffix so that is why I said "between" the hyphens.

Task:
1. Read File name and note the characters (possibly alpha numeric) between the hyphens. Example: PO9342567-0005-S1234
2. Open up an archive document that has all clipping paths associated with the pattern files.
3. Locate the and make active the path in the archive document that coincides with the characters between the first 2 hyphens of the pattern file name. (e.g 0005).
4. Copy the path from the archive to the pattern document (probably can be done by the action but if scriptable that would be great!)

Below is a video that I uploaded to YouTube to help show what I was hoping for. Sorry if it's not all that clear but it should help clarify what I said above.
http://youtu.be/8OGVl4GU_H8

Any help you can offer is very much appreciated!

Limey (Paul)

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Read filename for path name and copy path from 2nd document

Post by Mike Hale »

Paul, how much help do you need? One way to get the chars between the hyphens is with an regular expression. /.+-(.+)-.+/
Limey

Read filename for path name and copy path from 2nd document

Post by Limey »

Mike,
Unfortunately I have to admit that I need whatever help you can offer. I am up against a deadline and this script is a key part of the action set I am putting together. I will be getting all of the images/patterns clipped next week to go into the path archive/index file.

I have been thinking that the best way to do this would be to open the archive document so that it is always the 1st and foremost and then run the action that will include the script to copy over the path. If I do that it will avoid the need to open and close the path archive each time a new image is processed.

I think you understand what the end goal is and whatever you think will be the most efficient way to achieve it is good with me.

How much help do I need... Hmmm, a script? this is beyond my meager script adjusting capabilities. I haven't been able to find anything like it online.

As always a huge thanks to you and the rest of the gang here at PS-Scripts.
Paul(Limey)
Limey

Read filename for path name and copy path from 2nd document

Post by Limey »

Mike,
Thanks so much for the help... Here is the script that I am using that works great as part of my action. I hope that this helps others as it has me.

You are a genius my friend!

Code: Select allvar doc = app.activeDocument;// assumes the doc you want the path copied to is the activeDocument
var pathsDoc = app.documents[0];// assumes the document with the paths was the first doc open
var searchName = doc.name.match(/[^-]+-([^-]+)-.+/)[1];
app.activeDocument = pathsDoc;// now that we have the name switch to the paths doc
selectPathByName(searchName);
 executeAction( charIDToTypeID( "copy" ), undefined, DialogModes.NO );
 app.activeDocument = doc;
 executeAction( charIDToTypeID( "past" ), undefined, DialogModes.NO );
if(doc.activeLayer.isBackgroundLayer) doc.activeLayer.name = searchName;

function selectPathByName(pathName) {
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putName( charIDToTypeID('Path'), pathName );
    desc.putReference( charIDToTypeID('null'), ref );
    executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
};

Cheers!
Paul (Limey)