• 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

825

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

Copy link to clipboard

Copied

@Chandrakanthi26574696ugut

 

Sorry, my last reply was to @rob day.

 

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

In my example all of the returned widths should be the same because the 3 images have the same scaling applied, and the Javascript is setting the image rotations to 0, but I get different widths. I’ve attached my test example if you want to test.

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

Sorry, my example script is setting absoluteRotationAngle—rotationAngle works.

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

quote

Sorry, my example script is setting absoluteRotationAngle—rotationAngle works.


By @rob day

 

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

 

absoluteRotationAngle is "The rotation angle of the Image relative to its containing object. (Range: -360 to 360)" - and it looks like is the sum of all rotations of all parent objects. or maybe not?

 

rotationAngle is "The rotatation angle of the Image. (Range: -360 to 360)" - per Page / Document.

 

As per the screenshot I've posted earlier:

RobertTkaczyk_0-1704724463377.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
Guide ,
Jan 08, 2024 Jan 08, 2024

Copy link to clipboard

Copied

Hi @Chandrakanthi26574696ugut 

 

To my knowledge, the dimensions shown in the Transform panel always reflect the size of the inner bounding box of the selected object — assuming a single object is selected — BUT with respect to the scale factor of the inner-to-pasteboard matrix and using the ruler units, so you get relevant values that fit the viewport.

 

In general you can't get reliable information from the geometricBounds property. But contrary to what was said above, it is possible to calculate these values from transformation states, including for internal objects like Images, etc, which would not fit their container.

 

Also, the preference Dimensions Include Stroke Weight impacts the displayed dimensions, which can also be taken into account by the script.

 

I have just written the code below as a first sketch (not tested it in all possible conditions but gives fairly satisfactory results):

 

(function selTransformDimensions(  sel,VP,BBL,CS_IN,CS_PB,tl,br,mx,rw,rh,wu,hu)
//----------------------------------
// Display the dimensions of the selection (W,H)
// as shown in the Transform panel.
{
   const PRECISION = 1e4;

   sel = (app.selection||0)[0]||0;
   if( !sel.hasOwnProperty('resolve') ) return;
   
   VP = app.properties.activeDocument.viewPreferences;

   // Boring enums.
   BBL = +BoundingBoxLimits
   [
      app.transformPreferences.dimensionsIncludeStrokeWeight
      ? 'OUTER_STROKE_BOUNDS'
      : 'GEOMETRIC_PATH_BOUNDS'
   ];
   CS_IN = +CoordinateSpaces.innerCoordinates;
   CS_PB = +CoordinateSpaces.pasteboardCoordinates;

   // Inner bounding box corners -> inner dims (in pt)
   tl = sel.resolve([ [0,0], BBL, CS_IN ], CS_IN)[0];
   br = sel.resolve([ [1,1], BBL, CS_IN ], CS_IN)[0];
   w = br[0] - tl[0];
   h = br[1] - tl[1];

   // Compensate the scale factors relative to PB.
   mx = sel.transformValuesOf(CS_PB)[0];
   w *= mx.horizontalScaleFactor;
   h *= mx.verticalScaleFactor;

   // Use horiz./vert. ruler units (instead of pt)
   tl = sel.resolve( [[0,0],0], CS_PB, true)[0];
   br = sel.resolve( [[1,1],0], CS_PB, true)[0];
   rw = br[0]-tl[0];
   rh = br[1]-tl[1];

   // Final message.
   wu = 'W: ' + Math.round((PRECISION*w)/rw)/PRECISION
        + ' ' + VP.horizontalMeasurementUnits.toString();
   hu = 'H: ' + Math.round((PRECISION*h)/rh)/PRECISION
        + ' ' + VP.verticalMeasurementUnits.toString();
   alert( [wu,hu].join('\r') );

})();

 

Animation shows script behavior with various cases of (nested, rotated…) selection:

 

TransformDimensions.gif

I don't remember how the shear attribute is dealt with in the transform panel. This scenario might require a small adjustment of the proposed code… if you really need it.

 

Hope that helps.

 

Best,

Marc

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
Guide ,
Jan 09, 2024 Jan 09, 2024

Copy link to clipboard

Copied

[In addition to my previous message]

 

When a Shear X angle α is applied, the displayed height is updated accordingly (while width is not impacted), so we must divide h by cosα, where α ranges in ]-π/2,+π/2[. This leads to the fix below:

 

(function selTransformDimensions(  sel,VP,BBL,CS_IN,CS_PB,tl,br,mx,rw,rh,wu,hu,a)
//----------------------------------
// Display the dimensions of the selection (W,H)
// as shown in the Transform panel.
// [FIX240109] Now supporting Shear X angle.
{
   const PRECISION = 1e4;

   sel = (app.selection||0)[0]||0;
   if( !sel.hasOwnProperty('resolve') ) return;
   
   VP = app.properties.activeDocument.viewPreferences;

   // Boring enums.
   BBL = +BoundingBoxLimits
   [
      app.transformPreferences.dimensionsIncludeStrokeWeight
      ? 'OUTER_STROKE_BOUNDS'
      : 'GEOMETRIC_PATH_BOUNDS'
   ];
   CS_IN = +CoordinateSpaces.innerCoordinates;
   CS_PB = +CoordinateSpaces.pasteboardCoordinates;

   // Inner bounding box corners -> inner dims (in pt)
   tl = sel.resolve([ [0,0], BBL, CS_IN ], CS_IN)[0];
   br = sel.resolve([ [1,1], BBL, CS_IN ], CS_IN)[0];
   w = br[0] - tl[0];
   h = br[1] - tl[1];

   // Apply the scale factors (relative to PB).
   mx = sel.transformValuesOf(CS_PB)[0];
   w *= mx.horizontalScaleFactor;
   h *= mx.verticalScaleFactor;
   
   // [FIX240109] Apply the shear X angle (relative to PB).
   (a=mx.clockwiseShearAngle) && (h/=Math.cos(a*Math.PI/180));

   // Use horiz./vert. ruler units (instead of pt)
   tl = sel.resolve( [[0,0],0], CS_PB, true)[0];
   br = sel.resolve( [[1,1],0], CS_PB, true)[0];
   rw = br[0]-tl[0];
   rh = br[1]-tl[1];

   // Final message.
   wu = 'W: ' + Math.round((PRECISION*w)/rw)/PRECISION
        + ' ' + VP.horizontalMeasurementUnits.toString();
   hu = 'H: ' + Math.round((PRECISION*h)/rh)/PRECISION
        + ' ' + VP.verticalMeasurementUnits.toString();
   alert( [wu,hu].join('\r') );

})();

 

TransformDimsShear.png

Best,

Marc

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

Copy link to clipboard

Copied

LATEST

Thanks for the updates and new approach

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