how to resize a text frame to a given value
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.
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.
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],
];
};Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.