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

Transform properties width

Explorer ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

Hi

Is it possible to get the value shown in the width box in the tranform panel, through a script ?

 

I have tried substracting geometricbounds values, but for every embedded link(png/psd), the values are not matching.

TOPICS
Scripting , UXP Scripting

Views

906

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

correct answers 1 Correct answer

Participant , Jan 04, 2024 Jan 04, 2024

I am not aware of any alternative method to read the width of an element except using the geometricBounds coordinates.

 

Select an element and try this:

var gb = app.selection[0].geometricBounds;
var width = gb[3] - gb[1];

alert(width);

 

Votes

Translate

Translate
Participant ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

I am not aware of any alternative method to read the width of an element except using the geometricBounds coordinates.

 

Select an element and try this:

var gb = app.selection[0].geometricBounds;
var width = gb[3] - gb[1];

alert(width);

 

____________________
Robotic Process Automation in Desktop Publishing (Book): https://doi.org/10.1007/978-3-658-39375-5

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 ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

the values are not matching

 

Hi @Chandrakanthi26574696ugut , do you have the linked image or its parent container selected? They wouldn't necessarily have the same width.

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
Explorer ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

Hi the script is looping through all the graphics and calculating width on geometricbounds.

script is not selecting these links.

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 ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

script is not selecting these links.

 

But what are you selecting to check the Transform panel Width?

 

For example this gets both the linked image width and its container frame width, which is what‘s showing in the Transform panel when I select the frame :

 

 

var lnks = app.documents[0].links;

//an image, the link’s parent
var img = lnks[0].parent

//the image bounds and width
var ib = img.geometricBounds
var iw = ib[3]-ib[1]

//the image’s parent container frame bounds and width
var fb = img.parent.geometricBounds
var fw = fb[3]-fb[1]

alert("\rImage Width: " + iw + "\r" + "Container Width: " + fw)

 

 

Screen Shot 1.png

 

The image direct selected:

Screen Shot 2.png

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
Explorer ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

To verify width i am clicking on the links from the links panel.

 

I have tried with app.documents[0].links

 and app.documents[0].allgraphics 

Only for some links the values donot match. some are matchingthough. 

purpose of this script is to resize the images in photoshop using the values from indesign.

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 ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

Can you post some screenshots of what exactly are you talking about / looking for?

 

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 ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

Just to clarify a link doesn’t have a geometricBounds property—this throws an error when i try to get the geometricBounds of the first link:

 

var lnks = app.documents[0].links;
$.writeln(lnks[0].geometricBounds)
 
Can you post the code that’s returning the wrong width?

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 ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

Yes, Link doesn't have a geometric properties - as it aways needs a container - and only this container have geometric properties.

 

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
Explorer ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

Hi All

Thanks for responding to my queries so quickly.  I am pasting the script below and the indesign file against which i am running this script contains many links which i donot wish to attach here for privacy reasons .

 

var images = app.activeDocument.allGraphics;

var file = new File(Folder.myDocuments + "/inddsizes2.txt");
if (file.exists) {
file.remove();
}
for (var i=0; i<images.length; i++) {//images.length
        var eff = images[i].effectivePpi.toString();
     
        var pp = images[i].itemLink.parent;//image
        var cont = pp.parent;//cont



        if(eff.split(',')[0] > 320){
            var w = Math.round(pp.geometricBounds[3]-pp.geometricBounds[1]);
           
         
            if (file.exists) {
                file.open("a");
                var newData = images[i].itemLink.filePath+"-"+w+"\n"
                file.write(newData);
                file.close();
            } else {
                var data = images[i].itemLink.filePath+"-"+w+"\n"
                file.open("w");
                file.write(data);
                file.close();
            }
        }

        if(i == (images.length-1)){
            alert('files marked for PS')
        }

}

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 ,
Jan 05, 2024 Jan 05, 2024

Copy link to clipboard

Copied

Hi @Chandrakanthi26574696ugut , I’m not seeing a problem with the width part of your code, it’s returning the images’ widths. You are declaring a variable for the image’s frame (cont), but not using it.

 

Also you might need to check if the graphic is an image otherwise you would get an error when you try to get .effectiveResolution.

 

Here’s an example where I’m getting both the image and its frame widths:

 

var images = app.activeDocument.allGraphics;

var file = new File(Folder.desktop + "/inddsizes2.txt");
    if (file.exists) {
    file.remove();
}

//declare the loop variables
var ef, pp, cont, w, fw, data, newdata;
for (var i=0; i<images.length; i++) {//images.length
    
    //make sure the graphic is an image
    if (images[i].constructor.name == "Image") {
        pp = images[i]//the image
        cont = pp.parent;//the image frame
        eff = pp.effectivePpi; //returns the vertical and horizontal as an  array
        
        //if either the vertical or horizontal res exceeds 320
        if(eff[0] || eff[1] > 320){
            
            //the scaled image width
            w = Math.round(pp.geometricBounds[3]-pp.geometricBounds[1]);
            //the image frame width
            fw = Math.round(cont.geometricBounds[3]-cont.geometricBounds[1])
         
            if (file.exists) {
                file.open("a");
                newData = images[i].itemLink.filePath+"  -  Image Width: "+w+ "  Frame Width: " + fw + "\n"
                file.write(newData);
                file.close();
            } else {
                data = images[i].itemLink.filePath+"  -  Image Width: "+w+ "  Frame Width: " + fw + "\n"
                file.open("w");
                file.write(data);
                file.close();
            }
        }
    } 
    
   
    if(i == (images.length-1)){
        alert('files marked for PS')
    }
}

 

The result

 

Screen Shot 3.pngScreen Shot 4.png

 

Screen Shot 4.png

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 ,
Jan 05, 2024 Jan 05, 2024

Copy link to clipboard

Copied

Also, it might be better to capture the image info in a string and write the text file once at the end rather than including the file writes in the loop. Here I’m using a function to write the info once:

 

var file = new File(Folder.desktop + "/inddsizes2.txt")
var images = app.activeDocument.allGraphics;

//declare the loop variables
var ef, pp, cont, w, fw; 
var data = "Image Info: \n"; //a string to capture the image info
for (var i=0; i<images.length; i++) {
    
    //make sure the graphic is an image
    if (images[i].constructor.name == "Image") {
        pp = images[i]//the image
        cont = pp.parent;//the image frame
        eff = pp.effectivePpi; //returns the vertical and horizontal as an  array
        
        //if either the vertical or horizontal res exceeds 320
        if(eff[0] || eff[1] > 320){
            
            //the scaled image width
            w = Math.round(pp.geometricBounds[3]-pp.geometricBounds[1]);
            //the image frame width
            fw = Math.round(cont.geometricBounds[3]-cont.geometricBounds[1])
            //add to Image Info string
            data += images[i].itemLink.filePath+"  -  Image Width: "+w+ "  Frame Width: " + fw + "\n"
        }
    } 
    if(i == (images.length-1)){
        //write the text file once
        writeText(file, data)
        alert('files marked for PS')
    }
} 


/**
* Write a text file 
* @ param the file path 
* @ param the text 
* 
*/
function writeText(p,s){
    var file = new File(p);
    file.encoding = 'UTF-8';
    file.open('w');
    file.write(s);
    file.close();
}

 

 

 

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
Explorer ,
Jan 05, 2024 Jan 05, 2024

Copy link to clipboard

Copied

Hi 

Thank you for your valuable response and suggestions for improvising. 

 

As i mentioned in my earlier Post, only for some images the values are not accurate.

After consent from my team i am sending link to the file , where i am facing this issue.

Kindly download and let me know 

 

https://fromsmash.com/indesignfilesimagewidth

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 ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

I meant to ask if you were rotating your page items—geometricBounds gets the bounds of the image on the page including any rotation or skewing, so to get the actual scaled image width via geometricBounds you would have to set any rotation or skew to 0, get the geometric bounds, then reset.

 

Here the width of the image is 165.594mm, but the space it takes up on the page (geometricBounds) is 178.8mm.

 

Screen Shot 11.pngScreen Shot 12.png

 

 

I assume you plan to manually downsample the images over 320ppi in Photoshop? Why not let the downsampling happen on a PDF Export?

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 ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

Yeah, @rob day is right, after rotating - you'll get a different GeometricBound values.

 

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 ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

A doughnut from your document - left is the original one - right is after resetting rotation:

RobertTkaczyk_0-1704546328500.png

 

The value that is on the screenshot - InDesign values (top-left green rect) - are for the left object - image selected in the InDesign.

 

Highlighted in green are the values for the right object - after resetting angle to "0".

 

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 ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

I think, the easiest way to get what you want @Chandrakanthi26574696ugut through scripting, would be to check if image is rotated, unrotate it - by setting angle to 0 - rotation point doesn't matter, read GeometricBounds, calculate width, then just undo the rotation.

 

Maybe it could be done using Transformation Matrices - but I won't even try this method. 

 

But don't use Clear Transformation option - it will reset EVERYTHING - including scale, etc. 

 

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 ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

I think, the easiest way to get what you want @Chandrakanthi26574696ugut through scripting, would be to check if image is rotated, unrotate it - by setting angle to 0 - rotation point doesn't matter, read GeometricBounds, calculate width, then just undo the rotation.

 

Hi Robert, you would have to also clear any other parent rotations (and skews)—the parent frame, groups, groups inside of groups, etc. It gets messy if you want something that works for all cases.

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 ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

@rob day, no, you don't - image will be rotated to 0 - no matter what is the rotation angle of the all parent objects combined.

 

And when object is skewed / sheared - it is reflected in what InDesign returns for the rotated image - so if you clear skew / shear AND rotation - you'll get a different size - if you just unrotate.

 

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 ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

Groups of objects:

RobertTkaczyk_0-1704555051545.pngRobertTkaczyk_1-1704555075535.png

 

RobertTkaczyk_2-1704555113875.png

RobertTkaczyk_3-1704555127444.png

 

And here are the Width & Height values calculated from the GeometricBounds:

RobertTkaczyk_5-1704555245495.png

I'm not doing rounding - so values are "almost 0".

 

And full document's structure:

RobertTkaczyk_6-1704555613361.png

 

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 ,
Jan 07, 2024 Jan 07, 2024

Copy link to clipboard

Copied

If I add lines to set the image rotation and shear to 0 to @Chandrakanthi26574696ugut ‘s code I still get different width calculations for one of the example files.

 

Here the image on the right has no rotations and the image on the left was copied from the example file and has rotations applied to both the image and its frame—they are returning different widths even though there rotations have both been set to 0—the actual width is 166:

 

Screen Shot 16.png

 

The code with image rotation and shear set to 0

 

//Undo Command 
app.doScript(getImageWidths, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Get Image Widths');


function getImageWidths(){
    var file = new File(Folder.desktop + "/inddsizes2.txt")
    var images = app.activeDocument.allGraphics;
    
    //declare the loop variables
    var ef, pp, cont, w, fw; 
    var data = "Image Info: \n"; //a string to capture the image info
    for (var i=0; i<images.length; i++) {
        
        //make sure the graphic is an image
        if (images[i].constructor.name == "Image") {
            pp = images[i]//the image
            cont = pp.parent;//the image frame
            eff = pp.effectivePpi; //returns the vertical and horizontal as an  array
            
            //if either the vertical or horizontal res exceeds 320
            if(eff[0] || eff[1] > 320){
                pp.absoluteRotationAngle = 0;
                pp.absoluteShearAngle = 0
                //the scaled image width
                w = Math.round(pp.geometricBounds[3]-pp.geometricBounds[1]);
                //the image frame width
                fw = Math.round(cont.geometricBounds[3]-cont.geometricBounds[1])
                //add to Image Info string
                data += images[i].itemLink.name +"  -  Image Width: "+w+ "  Image rotation: " + pp.absoluteRotationAngle + "\n"
            }
        } 
        
    } 
    writeText(file, data)
    alert('files marked for PS')
}


/**
* Write a text file 
* @ param the file path 
* @ param the text 
* 
*/
function writeText(p,s){
    var file = new File(p);
    file.encoding = 'UTF-8';
    file.open('w');
    file.write(s);
    file.close();
}

 

 

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
Explorer ,
Jan 07, 2024 Jan 07, 2024

Copy link to clipboard

Copied

Hi Rob, Robert

 

Thanks for looking in to the files and providing a work around.

Though i am not sure of how the undo command works. Because it is placed on top of the other methods. I assumed it needs to be placed after the calculation ofthe width.

 

However i am going to try this script. 

 

Regarding downsampling, yes I have prepared a script for resizing in PS.  I was not aware of downsampling through PDF export until now. Will check that option as well. 

 

Will post further, in case of any hurdles.

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 ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

I was not aware of downsampling through PDF export until now

 

Besides the extra work there are other problems with resampling in Photoshop. The resample is destructive, so if you sampled everything to an effective resolution of 300, and sometime in the future decided to increase the scaling in the pagelayout, the output res is going to drop below the desired 300ppi

 

Photoshop does have different resampling methods, but I don’t think you would see any benefit over a PDF downsample in print. You would want to run some output tests before going to the extra work of a PS down sample.

 

A more reliable scripting solution would be to have the script open images that are over 320 PPI in Photoshop, which can be done with a BridgeTalk object. Here‘s an example:

 

 


checkRes()
var np;
function checkRes(){
    var bt = new BridgeTalk();  
    bt.target = "photoshop"; 
    if (app.documents.length > 0) {
        var lnks = app.documents[0].links;
        var img, eff, pa;
        for (var i = 0; i < lnks.length; i++){
            img = lnks[i].parent;
            if (img.constructor.name == "Image" && lnks[i].status == LinkStatus.NORMAL) {
                eff = img.effectivePpi; //returns the vertical and horizontal as an  array
                if(eff[0] || eff[1] > 320){
                    pa = lnks[i].filePath;
                    setImageRes(pa, eff, bt)
                }
            }
            /* try {
                lnks[i].relink(File(pa))
            }catch(e) {} */
        };   
    } else {
        alert("No Documents Open")
        return
    }
}


/**
* Image sampling
* @ param file path 
* @ param InDesign Effective res 
* @ param Bridgetalk instance 
* return new file path 
*/

function setImageRes(pa, ef, bt){
    bt.body = psScript.toString() + "\rpsScript('"+pa+"'"+",["+ef+"]);";
    //$.writeln(bt.body)
    bt.onError = function( inBT ) { alert(inBT.body); };  
    bt.onResult = function(resObj) { 
        np = resObj.body
     } 
     bt.send(1000);   
    function psScript(pa, ef) {  
        //Open the link
        var of = open (File(pa));
        //get the scaled resolution from the InDesign Effective resolution (ef)
        var rs = (of.resolution/ef[0])*of.resolution
        of.resizeImage(null, null,rs,ResampleMethod.BICUBICSHARPER);
        //additional commands and save...
        
        //return
    }  
};

 

 

 

 

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 ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

@rob day 

 

What you get from the script - when reading GeometricBounds - will always be different to what InDesign is showing - because InDesign is showing values for when rotation angle is set to "0".

 

I have no idea if it's calculated on the spot - or stored somewhere - but that's what I've observed. 

 

Of course I can be wrong. 

 

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
Explorer ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

Hi

 

There  is no change in the width of the images. For few images the width is still not accurate / not same as showin in indesign transform panel.

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