Skip to main content
Known Participant
March 2, 2023
Answered

Geometric Bounds

  • March 2, 2023
  • 2 replies
  • 1558 views

Hi,

I need to change the geometric values for the textframe so that I have given the values statically which is listed below and it works fine only for the unit 'Points'. My query is that I need to apply the geometric bound with all the units like 'inches, millimeter,centimeter and so on'.

var doc = app.activeDocument;
var frame = doc.pages[0].textFrames[0];
gb= [95.891, 37.5, 730.458, 576];
frame.geometricBounds = gb;

 

This topic has been closed for replies.
Correct answer rob day

Hi @Barathi , Another option is to set the measurement units the script will use:

 

 

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.activeDocument;
var frame = doc.pages[0].textFrames[0];
gb= [95.891, 37.5, 730.458, 576];
frame.geometricBounds = gb;
//reset so it doesn’t affect other scripts
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

 

What I want to do is provide geometric bound values using a panel

 

Also, if by panel you mean you are building a dialog, look at the built in dialog class, it has a measurementEditBox object which lets the user specifiy the unit and the returned value is the unit converted to points.

 

So this would create a number field that defaults to Inches. If I enter 20 mm the returned value is 56.693 points

 

 

var x;
makeDialog();
function makeDialog(){
    var theDialog = app.dialogs.add({name:"Enter a Number", canCancel:true});
    with(theDialog.dialogColumns.add()){
        staticTexts.add({staticLabel:"X:"});
    }
    with(theDialog.dialogColumns.add()){
        x = measurementEditboxes.add({editUnits:MeasurementUnits.INCHES, editValue:0, minWidth:90});
    }

    if(theDialog.show() == true){
        x = x.editValue;
        main()
        theDialog.destroy();
	}
}


function main(){
    $.writeln(x)
    //20mm returns 56.693 points
    //10in returns 720 points
}

 

 

 

2 replies

Loic.Aigon
Legend
March 2, 2023

You may indeed change documents' view preferences to match you input value unit. But don't forget to set those back once your work is done. 

However, I wouldn't change measurement units unless I have good reasons too because, you will basically edit the document and create undo history entries (modifying & reverting). Unless of course, you decide to make your script undoable for the whole part.

A possible lightly approach would be to use the UnitValue Object that can manage values out of InDesign DOM. In other words, this would change inches value to points with no impact to InDesign regarding units. But of course, you will want to check your document measurement units are in points:

Here a dummy example to extend height:

var doc = app.activeDocument;
var frame = doc.pages[0].textFrames[0];
gb= [95.891, 37.5, 730.458, 576];

var uv = new UnitValue("10in");
gb[3] = uv.as("pt");

frame.geometricBounds = gb;

More on this here:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#UnitValue.html

Robert at ID-Tasker
Legend
March 2, 2023

This should work:

 

gb= ["10.25mm", "10mm", "55.5mm", "100.10mm"];

 

Same with "inch" and the rest. 

 

Or you can change MeasurementUnits in the ViewPreferences. 

 

BarathiAuthor
Known Participant
March 2, 2023

Hi @Robert at ID-Tasker,

What I want to do is provide geometric bound values using a panel. Hence, I will be able to apply this to the Indesign document without specifying any units.

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
March 2, 2023

Hi @Barathi , Another option is to set the measurement units the script will use:

 

 

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.activeDocument;
var frame = doc.pages[0].textFrames[0];
gb= [95.891, 37.5, 730.458, 576];
frame.geometricBounds = gb;
//reset so it doesn’t affect other scripts
app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;

 

 

What I want to do is provide geometric bound values using a panel

 

Also, if by panel you mean you are building a dialog, look at the built in dialog class, it has a measurementEditBox object which lets the user specifiy the unit and the returned value is the unit converted to points.

 

So this would create a number field that defaults to Inches. If I enter 20 mm the returned value is 56.693 points

 

 

var x;
makeDialog();
function makeDialog(){
    var theDialog = app.dialogs.add({name:"Enter a Number", canCancel:true});
    with(theDialog.dialogColumns.add()){
        staticTexts.add({staticLabel:"X:"});
    }
    with(theDialog.dialogColumns.add()){
        x = measurementEditboxes.add({editUnits:MeasurementUnits.INCHES, editValue:0, minWidth:90});
    }

    if(theDialog.show() == true){
        x = x.editValue;
        main()
        theDialog.destroy();
	}
}


function main(){
    $.writeln(x)
    //20mm returns 56.693 points
    //10in returns 720 points
}