• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How I can generate a report of pictures coordinates?

New Here ,
Dec 11, 2012 Dec 11, 2012

Copy link to clipboard

Copied

Hi,

I need to extract the top left corner and bottom right corner coordinates of pictures in a document, with page number and images name.

I understand the way geometricbounds works, but I'm unable to understand how the images are bound with the coordinate.

Can Anyone help me!

Thanks

TOPICS
Scripting

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 11, 2012 Dec 11, 2012

Copy link to clipboard

Copied

Hi,

I guess you mean the coordinates of the masked images = coordinates of a page item¿

app.activeDocument.allGraphics will return a array of all graphics.

check if parent of the graphic is a page item and get the geometric- or visual bounds. returned Bounds: [y1,x1,y2,x2]. so get the pairs for topleft and bottomright.

The graphic itsself has got the properties parentPage and name.

So you've got all you want.

Hans-Gerd Claßen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 13, 2012 Dec 13, 2012

Copy link to clipboard

Copied

You may try this snippet:

#target Indesign

//check for active Document

if(app.documents.length != 0){

   var currDoc = app.activeDocument;

   //array to catch infos

    var  graphicsInfos = [];

      }else{

          //no open document

       exit();}

//necessary

currDoc.zeroPoint = [0,0];

//get Measurement Units as string, set ruler Origin to Page

with(currDoc.viewPreferences){

    var hUnit = horizontalMeasurementUnits.toString();

    var vUnit = verticalMeasurementUnits.toString();

    rulerOrigin    =  RulerOrigin.PAGE_ORIGIN;

        }

   

    //get all graphics of document

var getGraphics = currDoc.allGraphics;

for(var i = 0; i < getGraphics.length; i++){

    //create object to store graphic infos

    currInfo = new Object();

currGraphic = getGraphics;

//Position, on page

currInfo['Position'] = 'NaN'

if(currGraphic.parent.hasOwnProperty('visibleBounds')){

    currParentBounds = currGraphic.parent.visibleBounds;

    topLeft = '' + currParentBounds[1] + ' ' + hUnit + ' / ' + currParentBounds[0] + ' ' + vUnit;

    bottomRight =  '' + currParentBounds[3] + ' ' + hUnit + ' / ' + currParentBounds[2] + ' ' + vUnit;

    currInfo['Position'] = 'Position\n topLeft: ' + topLeft + ' | ' + 'bottomRight: ' + bottomRight;

    }

   

    currInfo['Page'] = 'Page: ' + currGraphic.parentPage.name;

    currInfo['Name'] = 'Name: ' + currGraphic.itemLink.name;

    //store infos of graphic in array

graphicsInfos.push(currInfo) ;

}

//arrayToString

l = graphicsInfos.length;

newString = currDoc.name + '\n';

while(l--){

    newString = newString + graphicsInfos.Name + '\n' + graphicsInfos.Page + '\n' + graphicsInfos.Position + '\n\n'

    }

//write file

    var _file = new File('~/Desktop/' + currDoc.name.replace(/indd/, '') + 'txt');

        _file.open( 'w' );

        _file.encoding = 'UTF-8';

    _file.write( newString );

    _file.close();

Report will be saved on the desktop. Indesign-Documentname + txt

Hope it'll run

Hans-Gerd Claßen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 13, 2012 Dec 13, 2012

Copy link to clipboard

Copied

Hi Hans, it didn't work, but I came up with this script, but I need to add page number

Here's the script I came up:

app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

list = [];

imgs = app.activeDocument.allGraphics;

unitname = getCurrentUnit();

for (i=0; i<imgs.length; i++)

{

left = imgs.parent.geometricBounds[1];

top = imgs.parent.geometricBounds[0];

bottom = imgs.parent.geometricBounds[3];

right = imgs.parent.geometricBounds[2];

// some fair rounding

switch (unitname)

{

  case 'px':

   left = roundMe(left, 1);

   top = roundMe(top, 1);

   bottom = roundMe(bottom, 1);

   right = roundMe(right, 1);

  

   break;

  case 'in':

   left = roundMe(left, 2);

   top = roundMe(top, 2);

   bottom = roundMe(bottom, 2);

   right = roundMe(right, 2);

 

   break;

  default:

   left = roundMe(left, 1);

   top = roundMe(top, 1);

   bottom = roundMe(bottom, 1);

   right = roundMe(right, 1);

}

list.push (imgs.itemLink.name+'\t'+'('+left+','+top+')'+'\t('+bottom+','+right+')' );

}

// alert (list.join('\r')); exit();

defaultFile = new File (Folder.myDocuments+"/"+app.activeDocument.name.replace(/\.indd$/i, '')+".txt");

if (File.fs == "Windows")

writeFile = defaultFile.saveDlg( 'Save report', "Plain text file:*.txt;All files:*.*" );

else

writeFile = defaultFile.saveDlg( 'Save report');

if (writeFile != null)

{

if (writeFile.open("w"))

{

  writeFile.encoding = "utf8";

  writeFile.write (list.join("\r")+"\r");

  writeFile.close();

}

}

function roundMe(val,to)

{

var t = 1;

while (to-- > 0) t *= 10;

return Math.round(val*t)/t;

}

function getCurrentUnit ()

{

switch (app.activeDocument.viewPreferences.horizontalMeasurementUnits)

{

  case MeasurementUnits.POINTS: return "pt";

  case MeasurementUnits.PICAS: return "pt";

  case MeasurementUnits.INCHES: return "in";

  case MeasurementUnits.INCHES_DECIMAL: return "in";

  case MeasurementUnits.MILLIMETERS: return "mm";

  case MeasurementUnits.CENTIMETERS: return "cm";

  case MeasurementUnits.CICEROS: return "c";

  case MeasurementUnits.AGATES: return "ag";

  case MeasurementUnits.PIXELS: return "px";

  default: alert ("Oh, come on!"); exit(0);

}

}

It's working, but I need the page number and I don't know how to insert the page number.

Have any idea?

Thanks for your help!

Patrick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 13, 2012 Dec 13, 2012

Copy link to clipboard

Copied

Hi,

it's tested for ID CS 5.5 Mac & PC -> Runs fine here.

(Won't run CS4 & prior)

Have a nice day

Hans-Gerd Claßen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2012 Dec 18, 2012

Copy link to clipboard

Copied

Thanks everyone for your help!

The script works, but I don't know why, I have an Error Number 21

Capture d’écran 2012-12-18 à 22.46.07.png

The script works with some files, but not with other. I don't understand why!

Also, I need to get the pictures from a specified layer.

Anyone have a suggestion?

I've worked with the script from Vandy.

Thanks for your help!

Patrick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2012 Dec 19, 2012

Copy link to clipboard

Copied

@Patrick – if "parentPage" returns "null", it means, that the object (the image, better: the  container that hold the image) resides on the pasteboard.

And therefore there could be no "parentPage".

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2012 Dec 19, 2012

Copy link to clipboard

Copied

Hi,

Thanks for the tips, an image was left outside the pasteboard!

The only thing left is to select only the pictures on a layer.

Have any idea about the script, I didn't find anything.

Thank you for your help!

Patrick

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 19, 2012 Dec 19, 2012

Copy link to clipboard

Copied

Hi,

a layer has got its own property 'allGraphics'.

Layers parent is the document. Any idea¿ Have a try!

Hans-Gerd Claßen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2012 Dec 20, 2012

Copy link to clipboard

Copied

@Hans-Gerd – but that method has one drawback:

the scope of "allGraphics" of a "layer" Object is restricted to "normal" document pages.
Graphics on master pages are left out there. You have to deal with them differently…

Some call it a bug, some call it "it's by design" 😉

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 20, 2012 Dec 20, 2012

Copy link to clipboard

Copied

Good to know thx Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 20, 2012 Dec 20, 2012

Copy link to clipboard

Copied

LATEST

I should have said:

"is restricted to "normal" document spreads", not "pages".


All graphics of containers on the pasteboards are included as well.

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 13, 2012 Dec 13, 2012

Copy link to clipboard

Copied

Try this:

app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

list = [];

currInfo = new Object();

imgs = app.activeDocument.allGraphics;

unitname = getCurrentUnit();

for (i=0; i<imgs.length; i++)

{

left = imgs.parent.geometricBounds[1];

top = imgs.parent.geometricBounds[0];

bottom = imgs.parent.geometricBounds[3];

right = imgs.parent.geometricBounds[2];

currInfo = 'Page: ' + imgs.parentPage.name;

// some fair rounding

switch (unitname)

{

  case 'px':

   left = roundMe(left, 1);

   top = roundMe(top, 1);

   bottom = roundMe(bottom, 1);

   right = roundMe(right, 1);

 

   break;

  case 'in':

   left = roundMe(left, 2);

   top = roundMe(top, 2);

   bottom = roundMe(bottom, 2);

   right = roundMe(right, 2);

   break;

  default:

   left = roundMe(left, 1);

   top = roundMe(top, 1);

   bottom = roundMe(bottom, 1);

   right = roundMe(right, 1);

}

list.push (imgs.itemLink.name+'\t'+'('+left+','+top+')'+'\t('+bottom+','+right+')' + '\t' + currInfo);

}

// alert (list.join('\r')); exit();

defaultFile = new File (Folder.myDocuments+"/"+app.activeDocument.name.replace(/\.indd$/i, '')+".txt");

if (File.fs == "Windows")

writeFile = defaultFile.saveDlg( 'Save report', "Plain text file:*.txt;All files:*.*" );

else

writeFile = defaultFile.saveDlg( 'Save report');

if (writeFile != null)

{

if (writeFile.open("w"))

{

  writeFile.encoding = "utf8";

  writeFile.write (list.join("\r")+"\r");

  writeFile.close();

}

}

function roundMe(val,to)

{

var t = 1;

while (to-- > 0) t *= 10;

return Math.round(val*t)/t;

}

function getCurrentUnit ()

{

switch (app.activeDocument.viewPreferences.horizontalMeasurementUnits)

{

  case MeasurementUnits.POINTS: return "pt";

  case MeasurementUnits.PICAS: return "pt";

  case MeasurementUnits.INCHES: return "in";

  case MeasurementUnits.INCHES_DECIMAL: return "in";

  case MeasurementUnits.MILLIMETERS: return "mm";

  case MeasurementUnits.CENTIMETERS: return "cm";

  case MeasurementUnits.CICEROS: return "c";

  case MeasurementUnits.AGATES: return "ag";

  case MeasurementUnits.PIXELS: return "px";

  default: alert ("Oh, come on!"); exit(0);

}

}

Vandy

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines