Hello, great@rob day I finally found you. It seems like you were the one who originally helped me modify the script. Now it is right for text boxes, since when I don't know, it doesn't seem to work for images or regular frames. Can you make the script differentiate between text frames, images, and regular frames? ① If it's a text frame, use the current function (auto-fit column width, or typearea). ②If it's a picture or a normal frame: zoom in proportionally to the width and fit the column width or typearea Thank you very much. This is the latest version. Fhe first script(Fit to ttypearea): // the current document
//Fit to ttypearea
var curDoc = app.activeDocument;
// there must be one selection with the selection-tool and the selection must be a textframe
if ( app.selection.length != 1 || app.selection[0].constructor.name != "TextFrame" ) {
( alert ( "please select textframe" ) );
exit();
}
// the current selection
var curSel = app.selection[0];
// the page of the current selection
var curPage = curSel.parentPage;
// set the zeroPoint to 0
var zP = curDoc.zeroPoint;
if (zP != [0,0]) {
curDoc.zeroPoint = [0,0];
}
// set the ruler to page origin and store the user-pref
var rO = curDoc.viewPreferences.rulerOrigin;
if (rO != 1380143215) {
curDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
}
// page width and height
var pW = curDoc.documentPreferences.pageWidth;
var pH = curDoc.documentPreferences.pageHeight;
var y1, x1, y2, x2;
// check if the page is a single, left or right page and store the margins
if ( curPage.side == PageSideOptions.leftHand ){
x2 = curPage.marginPreferences.left;
x1 = curPage.marginPreferences.right;
}
else {
x1 = curPage.marginPreferences.left;
x2 = curPage.marginPreferences.right;
}
y1 = curPage.marginPreferences.top;
x2 = pW - x2;
y2 = pH - curPage.marginPreferences.bottom;
var gB = curSel.geometricBounds;
// fit to margins
gB[0] = y1;
gB[1] = x1;
gB[2] = y2;
gB[3] = x2;
curSel.geometricBounds = gB;
// fitFrame(curSel);
// set the zeroPoint and ruler to the original state
resetAsBefore();
function fitFrame(aFrame) {
var gB = aFrame.geometricBounds;
gB[2] = gB[2]+ 50;
aFrame.geometricBounds = gB;
var lastBaseLine = aFrame.lines.lastItem().baseline;
aFrame.geometricBounds = [ gB[0], gB[1], lastBaseLine, gB[3] ];
}
function resetAsBefore() {
if ( rO != 1380143215 ) {
curDoc.viewPreferences.rulerOrigin = rO;
}
// set the zeroPoint back to the origin state
if (zP != [0,0]) {
curDoc.zeroPoint = zP;
}
} The second script(Fit to column) //set zero point, rulers and get selection
//Fit to column
var zp = app.activeDocument.zeroPoint;
var ro = app.activeDocument.viewPreferences.rulerOrigin;
app.activeDocument.zeroPoint = [0,0];
app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
var curSel = app.activeDocument.selection[0];
//the selection’s page
var pp = curSel.parentPage;
//selection bounds
var sb = curSel.visibleBounds;
//the left margin, and an array of column postions from left to right
var tm = pp.marginPreferences.top
var lm;
if (pp.side == PageSideOptions.RIGHT_HAND) {
lm = pp.marginPreferences.left
} else {
lm = pp.marginPreferences.right
};
var cp = pp.marginPreferences.columnsPositions;
var lcb, rcb;
//get the new left and right bounds based on the selection’s left edge
for (var i = 0; i < cp.length; i++){
if (sb[1] >= cp[i]+lm && sb[1] <= cp[i+1]+lm) {
lcb = cp[i]+lm;
rcb = cp[(i+1)]+lm
}else if (sb[1] < cp[0]+lm){
lcb = cp[0]+lm;
rcb = cp[1]+lm
}else if (sb[1] > cp[cp.length-1]){
lcb = cp[cp.length-1]+lm;
rcb = cp[cp.length-2]+lm
}
};
try {
curSel.visibleBounds = [sb[0], lcb, sb[2], rcb];
curSel.fit(FitOptions.FRAME_TO_CONTENT)
}catch(e) {}
app.activeDocument.zeroPoint = zp;
app.activeDocument.viewPreferences.rulerOrigin = ro;
... View more