Copy link to clipboard
Copied
I need to change the figure caption text frame size based on the figure width in a grouped objects
How to do this please advice.
Your informations and the code are not accurate! > Some parentheses are missing, expand the textframe 240 or to the width of the corresponding image?
However: While fit to content works in the UI, it expands the caption frame in my test to the right. So I decide to write a own function for the fitting.
...main();
function main() {
var curDoc = app.activeDocument;
var allGroups = curDoc.groups;
for (var i = 0; i < allGroups.length; i++) {
var curGroup = allGroups;
var pItems = curGroup.pageItems;
if (
Copy link to clipboard
Copied
Where is your visual example and your code tryout?
Copy link to clipboard
Copied
var myDoc = app.activeDocument;
var myGroup = myDoc.groups
for (var i =0;i<myGroup.length;i++)
{
var myname = myGroup.name;
for (var j= 0;j<myGroup.pageItems.length;j++)
{
var Bound = myGroup.pageItems
var height = Bound[2] - Bound[0];
var width = Bound[3] - Bound[1];
// $.writeln (width )
change_width = 240;
if (myGroup.pageItems
{
app.select(myGroup.pageItems
myStoreBounds = myGroup.pageItems
app.selection[0].geometricBounds = [myStoreBounds[0], myStoreBounds[1], myStoreBounds[2], myStoreBounds[1]+width ]
app.selection[0].fit(FitOptions.frameToContent);
app.select(myGroup.allPageItems);
myDoc.align (app.selection, AlignOptions.HORIZONTAL_CENTERS)
Copy link to clipboard
Copied
Your informations and the code are not accurate! > Some parentheses are missing, expand the textframe 240 or to the width of the corresponding image?
However: While fit to content works in the UI, it expands the caption frame in my test to the right. So I decide to write a own function for the fitting.
main();
function main() {
var curDoc = app.activeDocument;
var allGroups = curDoc.groups;
for (var i = 0; i < allGroups.length; i++) {
var curGroup = allGroups;
var pItems = curGroup.pageItems;
if (pItems.length != 2) { continue; }
for (var j = 0; j < pItems.length; j++) {
var curItem = pItems
.getElements()[0]; var constrName = curItem.constructor.name;
if (constrName == "Rectangle") {
var rect = curItem;
}
else if (constrName == "TextFrame") {
var tf = curItem;
}
}
var rectGB = rect.geometricBounds;
var tfGB = tf.geometricBounds;
tfGB[1] = rectGB[1];
tfGB[3] = rectGB[3];
tfGB[2] = tfGB[2] + 20;
tf.geometricBounds = tfGB;
fitFrame(tf);
}
function fitFrame(aFrame) {
var lastBaseLine = aFrame.lines[-1].baseline;
var b = aFrame.geometricBounds;
aFrame.geometricBounds = [b[0], b[1], lastBaseLine, b[3]];
}
}
Note: The script will check, if there are two page items in the group. It will not check, if those two items are textframe and rectangle, it assumes that it is correct.
Kai
Copy link to clipboard
Copied
Thank you so much. You are the lifesaver
Copy link to clipboard
Copied
I need to move the caption image right side of the image like below
How to do this
Copy link to clipboard
Copied
Feel free, to make a suggestion 😉
How would you do it in the UI? Note the steps and try to script it!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now