Copy link to clipboard
Copied
Hello,
I want to change the height of a text frame to a fixed value in mm, anchoring the text frame from top center.
No changes in width of text frame.
Please suggest a code.
Thanks and regards.
2 Correct answers
function main() {
var l = prompt("Please set type a line number (1 to 4)", "1");
resizeHeight(l);
}
main();
function resizeHeight(line) {
// app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
// app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
var sel = app.selection[0];
var w = 0;
switch (line) {
case "1":
w = 585.637;
break;
case "2":
w = 603.78;
break;
case "3":
w = 622.204;
bre
...
Hi @Moiz5FB2, well done on getting your script to work!
Just for your learning here is your same script but I've adjusted a few things to how I like them, and also used Robert's idea of using the `geometricBounds` to set the size. Using the `resize` method is just fine, too—this is just showing another way.
- Mark
const mm = 2.834645;
function main() {
var item = app.selection[0];
var lineCount = prompt("Please set type a line number (1 to 4)", "1");
if (!lineCount)
retu
...
Copy link to clipboard
Copied
I want to change the height of selected a text frame to a fixed value in mm, anchoring the text frame from top center, via a script.
No changes in width of text frame.
Copy link to clipboard
Copied
function main() {
var l = prompt("Please set type a line number (1 to 4)", "1");
resizeHeight(l);
}
main();
function resizeHeight(line) {
// app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
// app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
var sel = app.selection[0];
var w = 0;
switch (line) {
case "1":
w = 585.637;
break;
case "2":
w = 603.78;
break;
case "3":
w = 622.204;
break;
case "4":
w = 639.921;
break;
case "5":
w = 657.354;
break;
}
// alert(w);
sel.resize(
CoordinateSpaces.INNER_COORDINATES,
AnchorPoint.TOP_CENTER_ANCHOR,
ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
[325.984, w],
);
}
Copy link to clipboard
Copied
Hi @Moiz5FB2, well done on getting your script to work!
Just for your learning here is your same script but I've adjusted a few things to how I like them, and also used Robert's idea of using the `geometricBounds` to set the size. Using the `resize` method is just fine, too—this is just showing another way.
- Mark
const mm = 2.834645;
function main() {
var item = app.selection[0];
var lineCount = prompt("Please set type a line number (1 to 4)", "1");
if (!lineCount)
return;
setHeightByLineCount(item, lineCount);
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Frame Height');
function setHeightByLineCount(item, lineCount) {
app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
lineCount = Number(lineCount);
if (isNaN(lineCount))
return;
// get height value, in mm
// depending on line count
var height = [
0, // 0 lines
206.6, // 1 lines
213.0, // 2 lines
219.5, // 3 lines
225.7, // 4 lines
231.9, // 5 lines
][lineCount] * mm;
if (!height)
return;
// change height only using `geometricBounds` property:
item.geometricBounds = [
item.geometricBounds[0],
item.geometricBounds[1],
item.geometricBounds[0] + height,
item.geometricBounds[3],
];
};
Copy link to clipboard
Copied
Hi @m1b
Amusing challenge!
My two pennies: maybe we could make the whole setHeightByLineCount routine 100% agnostic. Here is a first draft that seems promising…
 
https://gist.github.com/indiscripts/742c3760fe08beea37496e0db4fba4d2
Best,
Marc
Copy link to clipboard
Copied
@Marc Autret, what fun! Beautiful!
- Mark
Copy link to clipboard
Copied
An improved version (undoable, bugfix, etc.) is now available in the IdGoodies repo:
→ https://github.com/indiscripts/IdGoodies/blob/master/full/SelSetFrameHeightByLineCount.jsx
Note that it also supports threaded frames ↓
Copy link to clipboard
Copied
Or you can read geometricBounds and modify 3rd value - [2] in JS notation - to [0]+height.

