use the file property of the placedItem or rasterItem if your images are embeded.
placedItem.file = File("c:\yourFolder\yourImage.png");
I was looking at another script you have made:
// script.name = relinkAllSelected.jsx;
// script.description = relinks all selected placed images at once;
// script.required = select at least one linked image before running;
// script.parent = CarlosCanto // 7/12/11;
// script.elegant = false;
var idoc = app.activeDocument;
sel = idoc.selection;
var file = File.openDialog ("open file");
for (i=0 ; i<sel.length ; i++ )
if (sel[i].typename == "PlacedItem")
var iplaced = sel[i];
iplaced.file = file;
alert("select at least one placed item before running");
And it got me thinking.
If the variable
sel was actually an array of all placedItems in the active document, and I added a .replace() method to the "iplaced.file = file" line. Then would this relink the image in the array?
Lets say the placed items path was \SERVER\SHARE FPO\DFolder\Image_1.psd and I sinply did a .replace(/ FPO/,"") so my path now read \SERVER\SHARE\DFolder\Image_1.psd
you got the idea, but no, it is not that easy, replace() is a method of the String Object, while the file property expects a File Object. In short File Object does not support the replace() method.
you'll have loop thru your selection, get the path of the placedItem, apply your replace() method to this path to make a new path, make a new File Object out of this new string, apply to the file property.
Still getting my head around the file/class/object/method/property terminology and their appropriate uses.
I'll try and get some quiet time and give it a go this week. I'll return with my results.
This is very helpful! I am jsut trying to get this work but I am kinda stuck in the part where I need to replace the path from my file object.
How would you do this?
Thanks in Advance!
what part are you having trouble with? what do you have so far?
I was struggling with creating a new file object but than I found a small snippet somewhere like: "var newFile = new file(pathToFile + fileName)"
That worked fine so far. But now I am dealing with the file extension. Do you may know any smart way to extract the extension of the selected file?