Copy link to clipboard
Copied
Hi ALL,
I want all image file naming like a caption in my source document. Source document contains more than 100 images.
But i got a script through the forum and tuned for my script. Still, the file naming comes for the Ist page image only.
From second page onwards the file naming not comes like a caption.
//To Get image file name
var tgt = app.activeDocument.rectangles;
for (i=0;i<tgt.length;i++){
myCaption = app.activeDocument.textFrames.add();
myCaption.textFramePreferences.verticalJustification = VerticalJustification.TOP_ALIGN
myCaption.contents = tgt.graphics[0].itemLink.name
myCaption.paragraphs[0].justification = Justification.CENTER_ALIGN;
bnds = tgt.visibleBounds;
myCaption.visibleBounds =
[bnds[2]+12, bnds[1], bnds[2]+4,bnds[3]];
//[bnds[0]-6, bnds[1], bnds[0]-1,bnds[3]];
myCaption.fit(FitOptions.FRAME_TO_CONTENT);
}
Thanks in advance
BEGINNER
If you use the add() method in conjunction with the document without specifying the page or better the spread, all objects added will end up on the first spread of your document.
But your testing scenario is also too narrow. You are expecting:
1. All your graphics are sitting in Rectangle objects (what about Ovals or Polygons?)
Therefore: All graphics placed in ovals or polygons are left out.
2. That really ALL rectangles in your document contain graphics
You are in trouble, if there happen to be emp
...Copy link to clipboard
Copied
If you use the add() method in conjunction with the document without specifying the page or better the spread, all objects added will end up on the first spread of your document.
But your testing scenario is also too narrow. You are expecting:
1. All your graphics are sitting in Rectangle objects (what about Ovals or Polygons?)
Therefore: All graphics placed in ovals or polygons are left out.
2. That really ALL rectangles in your document contain graphics
You are in trouble, if there happen to be empty rectangles on a page. I would suggest to test that with your script. It will give you an error, because there is no graphics[0] for this specific rectangle, where you can draw the "name" for the "itemLink".
3. That there are no graphics in anchored objects or pasted inside other objects; left alone graphics inside table cells.
And who can say that thiese three restrictions exist in all documents you want to run this script against?
So, if you want to get to all image files in the document, why don't you start with the images in the first place?
Let's see:
the Document object has an "allGraphics" property.
Use that as a starting point and you will not missing a single graphic.*
Iterate through "allGraphics" will get you:
the "name" of the placed image through its itemLink.name property;
the container of the graphic, that's the "parent" of the graphic.
Now you need one other thing:
the page, or even better(!) the spread where the graphic is located. Imagine a graphic sitting outside of a page.
If you want to handle thiese, you must know the spread.
If writing this script for InDesign CS5 or above, you are in luck. There is a "parentPage" property of the "Graphic" object, you could use for your add() method. For graphics outside of pages this property will be "null".
And another important thing:
if a graphic is copy/pasted from e.g. PhotoShop to InDesign, the "itemLink" property of that graphic is also "null".
We can handle that in a try/catch scenario…
//Scope: all graphics on all pages
//(that includes graphics of anchored objects, active states of MSOs, graphics in table cells as well)
var tgt = app.activeDocument.allGraphics;
for(var i=0;i<tgt.length;i++){
//Narrow the scope to all graphics on pages only:
if(tgt.parentPage != null){
//What to do with graphics, that are pasted directly from none-InDesign files:
//the caption will read "Undefined"
try{
var myName = tgt.itemLink.name;
}catch(e){var myName = "Undefined"};
//targets the page of the graphic:
var myPage = tgt.parentPage;
//adds a text frame to the page of the graphic:
var myCaption = myPage.textFrames.add();
myCaption.textFramePreferences.verticalJustification = VerticalJustification.TOP_ALIGN;
myCaption.contents = myName;
myCaption.paragraphs[0].justification = Justification.CENTER_ALIGN;
//Why visible bounds and not geometric bounds?
var bnds = tgt.parent.visibleBounds;
myCaption.visibleBounds = [bnds[2]+12, bnds[1], bnds[2]+4,bnds[3]];
myCaption.fit(FitOptions.FRAME_TO_CONTENT);
};
};
*Not exactly true, because it is missing graphics in not-active states of MultiStateObjects.
Since MSOs were introduced in InDesign CS5 the DOM documentation left out this fact so far.
//EDIT: in the first version I had a comment on a different scope. Since Document Objects have no "graphic" property, I removed that comment. Sorry.
Uwe
P.S. And a Happy New Year to all!
Message was edited by: Laubender
Copy link to clipboard
Copied
Hi Laubender,
Thanks for your reply.....
Thanks for your brief answer and your script.
Its realy good for lot of beginners.
NEW YEAR WISHES TO ALL FORUM MEMBERS....
Thanks
BEGINNER