0

Using current Indesign 2020; is there a way to create a text variable that divides the current object width/height by the metadata object (in frame) scale to get dimensions of the placed object in frame.

I use Indesign for proofing and am looking for a way to auto input width and height of placed art.

I have gone through all the metadata variables and nothing that I find will pull the actual dimensions from the (typically) pdf file.


Edit:

This is what I have so far:

var gb = app.activeDocument.selection[0].geometricBounds;
var up = gb[0];
var left = gb[1];
var down = gb[2];
var right = gb[3];
var artScale = app.activeDocument.selection[0].horizontalScale / 100;
var width  = (right - left) / artScale;
var height = (down - up) / artScale;
var dimTextW = app.activeDocument.pages[0].textFrames.add();
var dimTextH = app.activeDocument.pages[0].textFrames.add();
var wTxtPlace = [down, left, down + 2, right];
var hTxtPlace = [up, left - 1, down, left];

dimTextW.geometricBounds = wTxtPlace;
dimTextW.contents = width; 
dimTextH.geometricBounds = hTxtPlace; 
dimTextH.contents = height;

Edit: Stuck trying to find the language for getting the scale for the object in the frame without directly selecting it, and adding that calculation to the textFrame.

coursler
  • 1
  • 1
  • look for geometricBounds property of the placed object - returns array of four elements which will let you calculate the dimensions – Nicolai Kant Dec 11 '19 at 11:27

1 Answers1

0

Probably you need to change the line

var artScale = app.activeDocument.selection[0].horizontalScale / 100;

to

var artScale = app.activeDocument.selection[0].graphics[0].horizontalScale / 100;

Something like this:

var sel           = app.activeDocument.selection[0];       // selected frame
var scale         = sel.graphics[0].horizontalScale / 100; // scale factor

var gb            = sel.geometricBounds;

var width         = Math.round(-gb[1] + gb[3]);            // displayed width
var actual_width  = Math.round(width / scale);             // original width

var height        = Math.round(-gb[0] + gb[2]);            // displayed height
var actual_height = Math.round(height / scale);            // original height
Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23