Skip to main content
Lordrhavin
Inspiring
September 24, 2024
Answered

Resolving Page Resize Discrepancies Due to Unit Conversion in InDesign Scripts

  • September 24, 2024
  • 1 reply
  • 259 views

I'm trying to resize a page (dst) to the dimensions of a master page (src), this is what finally works:

 

 

 

function copyPageMetrics(src, dst) {
	var bounds = src.bounds;
	dst.resize(BoundingBoxLimits.GEOMETRIC_PATH_BOUNDS,
		AnchorPoint.TOP_LEFT_ANCHOR,
		ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,
		[bounds[3]*2.8346, bounds[2]*2.8346]);
}

 

 

 

I have the correct coordinates in bounds[3],bounds[2] (checked that with an alert()), but they didnt gave me the correct resize. To get the correct rresize, I had to multiply them with 2.8346, which is the factor of points in a mm.

Why? Why dont they use the same coordinate system? Is this always the case or do I have to get a page-specific translation-factor from somewhere?

<Title renamed by MOD>

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

Hi @Lordrhavin , By default the resize method’s width & height parameter is looking for points, so try setting your scripting preference units to points. This works for me:

 

var p = app.activeDocument.pages[1];
var am = p.appliedMaster.pages[0];
copyPageMetrics(am,p)


/**
* Resize page to master 
* @ param source masterpage 
* @ param page to resize 
* @ return void 
* 
*/
function copyPageMetrics(s,d){
    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
    var b = s.bounds
    d.resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.TOP_LEFT_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[b[3],b[2]])
    app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
}

 

 

 

 

 

1 reply

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
September 24, 2024

Hi @Lordrhavin , By default the resize method’s width & height parameter is looking for points, so try setting your scripting preference units to points. This works for me:

 

var p = app.activeDocument.pages[1];
var am = p.appliedMaster.pages[0];
copyPageMetrics(am,p)


/**
* Resize page to master 
* @ param source masterpage 
* @ param page to resize 
* @ return void 
* 
*/
function copyPageMetrics(s,d){
    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
    var b = s.bounds
    d.resize (CoordinateSpaces.INNER_COORDINATES,AnchorPoint.TOP_LEFT_ANCHOR,ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,[b[3],b[2]])
    app.scriptPreferences.measurementUnit = AutoEnum.AUTO_VALUE;
}