Copy link to clipboard
Copied
I have a large table imported from excel with embedded images in every alternative table row.
The images are in anchored frames in the table cells. I want to resize these frames and make the images match the new height. I can reference the table cell but not the anchored frame. Does anyone know how to go about this?
Hi @gnuklear ,
with ExtendScript you get all graphics (also images) of a table with:
table.allGraphics
This is an array.
To get to the container frames of the graphics in the array loop the array and ask for the parent of every entry.
DOM reference compiled by Gregor Fellenz:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Table.html
Regards,
Uwe Laubender
( Adobe Community Expert )
Hi @gnuklear, here's a quick little script to apply an Object Style to every graphic in a selected table. The idea is that you set the Size and Position and/or Frame Fitting Options of the object style. In the script, edit this line, replacing Table Graphic with the name of your object style:
var objectStyleName = 'Table Graphic';
Example Object Style settings:
You will see that the script uses the exact suggestion that @Laubender made. Let me know how it goes.
- Mark
/**
* @file Apply Objec...
Copy link to clipboard
Copied
Hi @gnuklear ,
with ExtendScript you get all graphics (also images) of a table with:
table.allGraphics
This is an array.
To get to the container frames of the graphics in the array loop the array and ask for the parent of every entry.
DOM reference compiled by Gregor Fellenz:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Table.html
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
@Laubender Thanks for the solution, used @m1b script to fix my table issues.
Copy link to clipboard
Copied
Hi @gnuklear, here's a quick little script to apply an Object Style to every graphic in a selected table. The idea is that you set the Size and Position and/or Frame Fitting Options of the object style. In the script, edit this line, replacing Table Graphic with the name of your object style:
var objectStyleName = 'Table Graphic';
Example Object Style settings:
You will see that the script uses the exact suggestion that @Laubender made. Let me know how it goes.
- Mark
/**
* @file Apply Object Style to Table Graphics.js
*
* Applies the specified object style to all graphics of selected table(s).
*
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/reference-an-anchored-frame-in-a-table-cell/m-p/14562435
*/
function main() {
// you must edit this to match your object style
var objectStyleName = 'Table Graphic';
var doc = app.activeDocument,
items = doc.selection;
if (0 === items.length)
return alert('Please select some page items and try again.');
var objectStyle = doc.objectStyles.itemByName(objectStyleName);
if (!objectStyle.isValid)
return alert('Could not find "' + objectStyleName + '" object style.');
for (var i = items.length - 1, item; i >= 0; i--) {
if (
items[i].parent.hasOwnProperty('tables')
&& items[i].parent.tables.length > 0
)
items[i] = items[i].parent;
else if (0 === items[i].tables.length)
continue;
// apply the object style to each graphic of each table of each item
for (var j = 0; j < items[i].tables.length; j++)
for (var k = items[i].tables[j].allGraphics.length - 1; k >= 0; k--)
items[i].tables[j].allGraphics[k].parent.appliedObjectStyle = objectStyle;
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Apply Object Style to Table Graphics');
Copy link to clipboard
Copied
@m1b Thanks for this. It saved me a lot of time.
Copy link to clipboard
Copied
You can check a cell to see if it has any page items (meaning anchored): aCell.pageItems.length
Copy link to clipboard
Copied
@brian_p_dts Good point! @Laubender and I have assumed that they are the only graphics in the table, but that might not be true, in which case we will definitely have to check the cell or, more likely, column. We'll see what @gnuklear says.
- Mark
Copy link to clipboard
Copied
Hi together,
table.allGraphics
has the advantage to get all graphics in the table.
Also graphics in nested table cells ( table inside a table cell ),
graphics in anchored text frames as well. Or anchored group of objects.
So one should be cautious what to do with the graphics and their container frames.
Also consider graphics in graphic cells that by definition are not anchored.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Thanks for this. Your solution of looping through the image array and scaling the parent container saved me a lot of time.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more