Page 1 of 1

identifying Photoshop or Illustrator layers in Project

Posted: May 25th, 2014, 12:24 pm
by Mikeoverbeck
Hello!
I am working on a re-linking script that is working very well so far. The only blind spot of this script is that I am unable to correctly change the linking of a project item that is an unmerged photoshop or Illustrator layer. Linking the item to a different yet identical PSD via scripting just connects it to the merged PSD. For that matter, is there any way to accurately identify a project item as an unmerged psd or ai layer? Currently my script identifies them by their file extensions and by identifying the '/' in the item name, and skips them leaving the re-linking up to the user. Certainly not airtight for those who like to rename items in their project window.

The goal of my script is to take a collected aep and re-link all footage items back to their original assets. Any help is appreciated!
-Mike O

Re: identifying Photoshop or Illustrator layers in Project

Posted: June 29th, 2014, 11:26 am
by axymark
Hi Mikeoverbeck,

I had the same problem (psd's only though, no ai) and in the end i resorted to saving a project as .aepx and editing out xml. It wasn't fun but it worked. Unfortunately i cannot share the script but i could post a snippet related to xml parsing tomorrow if it helps.

Re: identifying Photoshop or Illustrator layers in Project

Posted: June 30th, 2014, 1:56 pm
by Mikeoverbeck
Thanks for the reply. I hadn't thought about parsing through the XML. I would love to see a snippet that you could share. I would have to rewrite much of my script to have it work on XML, but it may be the only airtight way. Does your finished script happen to do what I'm attempting? No need to reinvent the wheel.
-Mike

Re: identifying Photoshop or Illustrator layers in Project

Posted: July 1st, 2014, 10:41 am
by axymark
In fact, it does exactly that. Obviously, the psd files have to be identical or at least identically structured.
Here's the code:

Code: Select all

// psdFileData is a multidimentional array which contains both source and 
// destination paths for each psd file.
// eg: [D:\folder1\myfile.psd,D:\folder2\myfile\myfile.psd]

// parse XML and replace PSD paths
if (psdFileData.length > 0) {
    xmlFile.open("r");
    var xmlString = xmlFile.read();
    var xmlData = new XML(xmlString);
    default xml namespace = "http://www.adobe.com/products/aftereffects";
    xmlFile.close();
    
    var relativeIndexIntoFullpathLength = (folder2 + "/").length;
    var pathNodes = xmlData.Fold.Item.xpath ("//*[@fullpath]");
    
    for (var i = 0; i < pathNodes.length(); i++) {
        var referenceFullpath = pathNodes[i].@fullpath.toString();
        var xmlFileIndex = findInMulDimArray(psdFileData, 0, referenceFullpath);
        if (xmlFileIndex != -1) {
            pathNodes[i].@fullpath = psdFileData[xmlFileIndex][1];
            pathNodes[i].@relativeAscendCountFromProject = "1";
            pathNodes[i].@relativeIndexIntoFullpath = relativeIndexIntoFullpathLength;
        }
    }
    
    xmlFile.open("w");
    xmlFile.write(xmlData);
    xmlFile.close();
}

// find a match in an element of a subarray
function findInMulDimArray(searchArray, searchIndex, searchString) {
    for (var i = 0; i < searchArray.length; i++) {
        if (searchArray[i][searchIndex] === searchString) {
            return i;
        }
    }
    return -1;
}