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

# get scale (h, v)

Community Beginner ,
Feb 20, 2018 Feb 20, 2018

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

918

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
8 Replies 8
People's Champ ,
Feb 21, 2018 Feb 21, 2018

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+"%");`

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

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

Report

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

Copied

Does applescript not have the trig math operations?

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

Copied

Hi Loic,

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

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

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!

Report

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

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);  }//---------------}`

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

Copied

Bon travail!

Merci de l'avoir partagé.

Report

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

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