i managed to get most of the script, there was a problem with the path and naming but now I am nearly there. The problem is that i cannot place the linked file. I always get an error of this sort: My code is below: and i call the place function here: //placeEvent(3, new File(winPath), true, 0, 0); placeLink(winPath); function placeLink(fileName){ var d = new ActionDescriptor(); var d1 = new ActionDescriptor(); var d2 = new ActionDescriptor(); d.putInteger(stringIDToTypeID("ID"), 3); d.putPath(stringIDToTypeID("null"), new File(fileName)); d.putBoolean(stringIDToTypeID("linked"), true); d.putObject(stringIDToTypeID("openAs"), stringIDToTypeID("null"), d1); d.putEnumerated(stringIDToTypeID("freeTransformCenterState"), stringIDToTypeID("quadCenterState"), stringIDToTypeID("QCSAverage")); d2.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), 0); d2.putUnitDouble(stringIDToTypeID("vertical"), stringIDToTypeID("pixelsUnit"), 0); d.putObject(stringIDToTypeID("offset"), stringIDToTypeID("offset"), d2); executeAction(stringIDToTypeID("placeEvent"), d, DialogModes.NO); } function placeEvent(ID, null2, linked, horizontal, vertical) { var descriptor = new ActionDescriptor(); var descriptor2 = new ActionDescriptor(); var descriptor3 = new ActionDescriptor(); descriptor.putInteger( stringIDToTypeID( "ID" ), ID ); descriptor.putPath( charIDToTypeID( "null" ), null2 ); descriptor.putBoolean( stringIDToTypeID( "linked" ), linked ); descriptor.putObject( stringIDToTypeID( "openAs" ), charIDToTypeID( "null" ), descriptor2 ); descriptor.putEnumerated( stringIDToTypeID( "freeTransformCenterState" ), stringIDToTypeID( "quadCenterState" ), stringIDToTypeID( "QCSAverage" )); descriptor3.putUnitDouble( stringIDToTypeID( "horizontal" ), stringIDToTypeID( "percentUnit" ), horizontal ); descriptor3.putUnitDouble( stringIDToTypeID( "vertical" ), stringIDToTypeID( "percentUnit" ), vertical ); descriptor.putObject( stringIDToTypeID( "offset" ), stringIDToTypeID( "offset" ), descriptor3 ); executeAction( stringIDToTypeID( "placeEvent" ), descriptor, DialogModes.NO ); } function modWinPath(path){ var newchar = '\\\\'; var winPath; winPath = path.split('/').join(newchar); winPath = winPath.replace("\\\\d\\\\", "d:\\\\"); winPath = winPath.replace("\\\\c\\\\", "c:\\\\"); return winPath; } var doc = app.activeDocument; var fName = doc.name.split("."); var fName = fName[0]; var layerN = doc.activeLayer.name; var linkFolder = Folder.selectDialog("Selection prompt"); if(linkFolder !== null){ var linkFolderPath = linkFolder.path; var linkName = linkFolder.name; var linkFullPath = linkFolderPath+"/"+linkName; function traverseFolder(path, layerN) { var folder = new Folder(path); suffix = new Array(); suffix[0] = "tif"; suffix[1] = "dng"; suffix[2] = "psd"; var files = folder.getFiles(); for (var i = 0; i < files.length; i++) { if (files instanceof File) { var fullPathName = Folder.decode(files); var fileName = files.name; fileName = decodeURI(fileName); for(var s = 0; s < suffix.length ; s++){ search_name = layerN + "." + suffix ; search_NAME = layerN + "." + suffix .toUpperCase(); if ((fileName == search_name) || (fileName == search_NAME)) { foundFile = fullPathName; var winPath = modWinPath(foundFile); alert("Try to place:\n" + winPath); //placeEvent(3, new File(winPath), true, 0, 0); placeLink(winPath); } } } else { traverseFolder(files, layerN); } } } traverseFolder(linkFullPath, layerN); }
... View more