identifying Photoshop or Illustrator layers in Project

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Mikeoverbeck
Posts: 4
Joined: May 23rd, 2014, 10:38 pm

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
User avatar
axymark
Posts: 23
Joined: November 29th, 2013, 7:04 am

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.
Mikeoverbeck
Posts: 4
Joined: May 23rd, 2014, 10:38 pm

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
User avatar
axymark
Posts: 23
Joined: November 29th, 2013, 7:04 am

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;
}
Post Reply