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

get scale (h, v)

Community Beginner ,
Feb 20, 2018 Feb 20, 2018

Copy link to clipboard

Copied

Hi,

I need help, I need to know the scale percentage of the image placed in illustrator. I can get it from matrix,  but after I rotate the image,  everything changed. What I need is exactly the same what I see in Link Information  " scale (h, v)"    - this when you double click the image from the link panel.

Thank you.

TOPICS
Scripting

Views

1.1K

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
Adobe
People's Champ ,
Feb 21, 2018 Feb 21, 2018

Copy link to clipboard

Copied

Seems like nothing works best than matrices:

alert("Horizontal Scale : "+Math.round((app.selection[0].matrix.mValueA*100)*100)/100+"\r"+"Vertical Scale : "+Math.round((app.selection[0].matrix.mValueD*100)*100)/100+"%");

Capture d’écran 2018-02-21 à 16.29.26.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 Beginner ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Thanks for the help!!!

But if forgot to mention that I'm using applescript .

Anyway, I found this...    do shell script "ruby -e 'puts Math.atan2(" & mvalue_b of m & "," & mvalue_a of m & ") / Math::PI * 180'"  by this will give the rotation percentage of the image.

So I use it to rotate back my image to 0 deg to get the right scale percentage:

set z to selection

set x to do shell script "ruby -e 'puts Math.atan2(" & mvalue_b of m & "," & mvalue_a of m & ") / Math::PI * 180'"

set y to get mvalue_b of matrix of the selection

                      

if y is not equal to 0 then

rotate z angle x about top right

set z to get mvalue_a of matrix of the selection

undo

else

set z to get mvalue_a of matrix of the selection

end if

this works for me, but if you can still give me a better syntax, ill appreciate.  Thank you!

Jhon

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
Valorous Hero ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Does applescript not have the trig math operations?

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 ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Hi Loic,

I agree to your solution. However, we can't get correct scale when it had a rotatation angle like below.

スクリーンショット 2018-02-23 11.14.33.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 ,
Feb 22, 2018 Feb 22, 2018

Copy link to clipboard

Copied

Here is a PoC code, get scale from rotated image.

var tg = app.selection[0];

var mx = tg.matrix;

var deg = Math.atan2(mx.mValueB, mx.mValueA) * 180 / Math.PI;

var nm = new Matrix;

nm.mValueA = nm.mValueD = 1;

nm.mValueB = nm.mValueC = 0;

var rtmx = app.concatenateRotationMatrix(nm, deg);

var sc = mx.mValueA / rtmx.mValueA;

alert(sc);

I'm stacking math a few month ago. Thank you for your info jhonperezph!

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
Advocate ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

Bonjour,

merci Ten A

// JavaScript Document Illustrator

// elleere Sun, 25 February 2018 21:08:12 GMT

{

  if (selection) {

  var sel = selection[0];

    if(sel.typename=='RasterItem' || sel.typename == 'PlacedItem') {

      var propT =  getscale1(sel);

      alert("scale1(H,V) : ("+propT.H+"%, "+propT.V+"%), Rotation : "+propT.A+" °");

      var propT =  getscale2(sel);

      alert("scale2(H,V) : ("+propT.H+"%, "+propT.V+"%), Rotation : "+propT.A+" °");

    }

  }

//---------------

  function  getscale1(tg) {

    var mtx, deg, degArd, scH, scV;

        mtx = tg.matrix;

        deg = Math.atan2(mtx.mValueB, mtx.mValueA) * 180 / Math.PI;

        degArd =getArrondi(deg,3);

        tg.rotate(-deg);

        mtx = tg.matrix;

        scH = getArrondi(mtx.mValueA * 100,3);

        scV = getArrondi(mtx.mValueD * 100,3);

        tg.rotate(deg);

        return {H:scH,V:scV,A:degArd}

    }

  function getscale2(tg){

    var mx, deg, degArd, nm, rtmx,scH, scV;

        mx = tg.matrix;

        deg = Math.atan2(mx.mValueB, mx.mValueA) * 180 / Math.PI;

        degArd =getArrondi(deg,3);

        nm = new Matrix;

        nm.mValueA = nm.mValueD = 1;

        nm.mValueB = nm.mValueC = 0;

        rtmx = app.concatenateRotationMatrix(nm, deg);

        scH = getArrondi(mx.mValueA / rtmx.mValueA * 100,3);

        scV = getArrondi(mx.mValueD / rtmx.mValueD * 100,3);

        return {H:scH,V:scV,A:degArd}

  }

  //---------------

  function getArrondi(nb,N) {

  //arrondi nb a N chiffres apres la virgule

  return Math.round(Math.pow(10,N)*nb)/Math.pow(10,N);

  }

//---------------

}

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 ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

Bon travail!

Merci de l'avoir partagé.

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
Advocate ,
Feb 26, 2018 Feb 26, 2018

Copy link to clipboard

Copied

LATEST

Rectificatif pour le script donné plus haut :

Inverser la valeur de l'angle

deg = -Math.atan2(mtx.mValueB, mtx.mValueA) * 180 / Math.PI;

scV valeur absolue

scV = Math.abs(getArrondi(mx.mValueD / rtmx.mValueD*100,3));

Désolé LR

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