Hi,
I try to place an image in a rectangle by name ...
var myDoc = app.activeDocument;
var myGraphicFile = File("/data/image.jpg");
// this code work
myDoc.rectangles.item(0).place(myGraphicFile);
//or
var img = myDoc.rectangles.item(0).place(new File(myGraphicFile));
//this code doesn't work
myDoc.rectangles.item("Rec1").place(myGraphicFile);
//or
var img = myDoc.rectangles.item("Rec1").place(new File(myGraphicFile));
Have you an idea ?
Thanks
How did you name it?
Rec1 = myDoc.rectangles.add()
In which case you need to use
myDoc.rectangles.item(Rec1).place(myGraphicFile);
without the "quotes" ![]()
If you used "name"
myDoc.rectangles.add({name:"Rec1"})
Then your code works ![]()
If you used "label"
myDoc.rectangles.add({label:"Rec1"})
then that's not good
If you want to refer to it, AFAIK you have to loop through all the rectangles and see if there label is =="Rec1"
Let us know if this solves your problem
Trevor
Hi Kasyan,
Thanks for your function ;-) It's a solution for my problem.
var myDoc = app.activeDocument;
var myGraphicFile = File("/data/image.jpg");
myRec.place(myGraphicFile);
var myRec = GetItemFromCollection("Rec1", myDoc.rectangles);
//or
var img = myRec.place(new File(myGraphicFile));function GetItemFromCollection(label, collection) {
for (var i = 0; i < collection.length; i++) {
if (label == collection[i].label) return collection[i];
}
return null;
}
But I would like understand why "myDoc.rectangles.item("Rec1").place(myGraphicFile);" don't work ... :-)
Rgds
Ronald
Hi Ronald
I'm pretty sure it's because labels as apposed to names are not intrinsically unique, so they can't be considered an identifier (which have to be unique).
Haven't put that so well but you should be able to understand.
Don't forget to mark your question as answered
Regards
Trevor
North America
Europe, Middle East and Africa
Asia Pacific