Copy link to clipboard
Copied
Hi All,
I have a multi-page document that has been in-line data merged. Each frame contains a table with 2 rows -- an image on top and text on the bottom (Image 1). I wrote a script that will find/select the text and apply an object style to that box. However, I can't seem to figure out how to script finding and selecting the larger image frame on the top to apply an object style to that box (Image 2). The 3rd and 4th image areas won't work with my object style, so those areas can't be selected. Any suggestions? Each page has 5-9 boxes, like the sample below, and I don't want to manually select each image frame to apply the object style.
Hello @jimDcleveland,
Take a look at the link below...
"Script to apply an Object Style to the frames those has same specific link image"
Regards,
Mike
This should help.
function main(){
//-----VARS-------//
var doc = app.documents, gfxs = [], n = 0, p, c, gfx, os, cl;
//Exit if no doc open
if(!doc.length) return;
doc = doc[0];
//Exit if object style not found
os = doc.objectStyles.itemByName("shadow");
if(!os.isValid){
alert("An object style named \"shadow\" is needed to run teh script.");
return;
}
//Let's loop through the array of graphics objects inside docs
gfxs = doc.allGraphic
...
Hello,
I modified the script. There was obviously a flaw with graphic cells and just in case, if tables are 1 cell only. The file you provided helped fixing the issue. This happens when you script blindly 😉
Apart from that, you can certainly have a prompt but think wisely, you may have many graphics and the user could be annoyed by repeating requests. At this point, you can either go with the dialogs object:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Dialogs.html#d1e590161
You sho
...Copy link to clipboard
Copied
There would be different ways to tackle this, the smarter one depends on your context.
- Do you want any images to be styled?
Then you could either loop through the doc.allGraphics array and climb up to the container.
- Only those mounted by the merge?
In other words, what are the key characteristics for being sure only the appropriate images are processed?
Copy link to clipboard
Copied
Hi Loic! Thank you for helping! I'm looking for only those mounted by the merge. For example, only the images that appear in that top frame with the text underneath.
Copy link to clipboard
Copied
Hello @jimDcleveland,
Take a look at the link below...
"Script to apply an Object Style to the frames those has same specific link image"
Regards,
Mike
Copy link to clipboard
Copied
This should help.
function main(){
//-----VARS-------//
var doc = app.documents, gfxs = [], n = 0, p, c, gfx, os, cl;
//Exit if no doc open
if(!doc.length) return;
doc = doc[0];
//Exit if object style not found
os = doc.objectStyles.itemByName("shadow");
if(!os.isValid){
alert("An object style named \"shadow\" is needed to run teh script.");
return;
}
//Let's loop through the array of graphics objects inside docs
gfxs = doc.allGraphics;
n =gfxs.length;
while(n--){
//let's climb up to what should be a cell.
gfx = gfxs[n];
//The container of the image
p = gfx.parent;
// a character containing a anchored fralme, a cell or a table object or something else
c = p.parent;
//a cell or a table object or something else
cl = c.parent;
//If the graphics hierarchy returns a cell or table object, let's apply object style to the graphic
if(
/^(Cell|Table)$/.test(c.constructor.name)
||
/^(Cell|Table)$/.test(cl.constructor.name)
){
p.applyObjectStyle(os)
}
}
}
//run
main();
[EDIT] Fix case with graphic cells and possible 1 cell only tables.
Copy link to clipboard
Copied
Thank you so much, Loic. I'll test the script tonight and let you know!
Copy link to clipboard
Copied
Hi Loic,
Thanks again for your help! It is really appreciated!
I could only get the script to work if I commented out this line:
Copy link to clipboard
Copied
Hello,
I modified the script. There was obviously a flaw with graphic cells and just in case, if tables are 1 cell only. The file you provided helped fixing the issue. This happens when you script blindly 😉
Apart from that, you can certainly have a prompt but think wisely, you may have many graphics and the user could be annoyed by repeating requests. At this point, you can either go with the dialogs object:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Dialogs.html#d1e590161
You should get the InDesign Scripting guide which introduces dialogs in a more friendly way.
Or use ScriptUI, see Peter Karhel reference book :
https://creativepro.com/files/kahrel/indesign/scriptui.html
HTH
Loic
Copy link to clipboard
Copied
Thank you, Loic! You have been super helpful (as always)!
I'll certainly check out the links that you provided. I didn't know that Peter Karhel wrote that ScriptUI guide! Good to know.
Take care and I appreciate your help!
Jim
Copy link to clipboard
Copied
@mikesorry our posts crossed each other. If I saw your first, I wouldn't have posted an answer 😉