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

How to reset Scale percentage using script

Explorer ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

Hi all,

I have following question: How can I reset horizontally and vertically scale of current selected image to 100% while maintaining current image dimensions (90x127.284mm)?

screenshot.png

Thanks in advance!

TOPICS
Scripting

Views

2.2K

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

People's Champ , Aug 11, 2019 Aug 11, 2019

app.selection[0].redefineScaling();

Have I misunderstood the question?

Ariel

Votes

Translate

Translate
Participant ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

        var mySel=app.selection;

           mySel.graphics[0].horizontalScale = 100;

   mySel.graphics[0].verticalScale = 100;

   mySel.fit(FitOptions.FRAME_TO_CONTENT);

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 ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

Unfortunetly it doesn't work.

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
Participant ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

sorry line 1 edit; var mySel=app.selection[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
Explorer ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

Nope. Scale is still unchanged.

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
Participant ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

var mySel=app.selection[0]; 

        if (mySel.constructor.name != "Rectangle") {

mySel=mySel.parent;

    }

mySel.graphics[0].horizontalScale = 100; 

mySel.graphics[0].verticalScale = 100; 

mySel.fit(FitOptions.FRAME_TO_CONTENT); 

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
People's Champ ,
Aug 09, 2019 Aug 09, 2019

Copy link to clipboard

Copied

Hello,

Just use InDesign feature :

var menuAction = app.menuActions.itemByName("$ID/RedefineScalingMenuString");

  menuAction.enabled && menuAction.invoke()

If needed in InDesign Server, then you will need to do some maths and call resize function.

FWIW

Loic

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 ,
Aug 10, 2019 Aug 10, 2019

Copy link to clipboard

Copied

Hi Loïc,

That's probably one of the best examples of invoking a MenuAction!

In terms of transformations, “Redefine Scaling as 100%” is much more complex than I imagined. There are probably good solutions using resize() and/or (horizontal/vertical)Scale properties. But from an educational standpoint it's interesting to implement that function strictly using the transformation and coordinate space API.

What is required here is:

(0) backup the original scaling factors,

(1) apply a 100% scaling with ajustScalingPercentage turned on,

(2) restore the original scaling factors with applyToContent turned on.

Surprisingly complicated! I did not manage to emulate the command in a more compact way:

function redefineScalingAs100(/*Image|<ImageContainer>*/sel,  img,p,orig,mx,pf,t)

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

// Emulate the "Redefine Scaling as 100%" menu action through

// detailed transform steps. As shown by Loic Aigon, invoking

// `app.menuActions.itemByName("$ID/RedefineScalingMenuString")`

// does the entire job in one single command. The present snippet

// attempts to reach the same outcome from pure transformations.

{

    // Checkpoint.

    // ---

    if( !sel ){ alert("Select an image."); return; }

    // ---

    ( sel instanceof Image )

    ? ( p=(img=sel).parent )

    : ( img=(p=sel).hasOwnProperty('images') && p.images[0] );

    // ---

    if( !img.isValid ){ alert("No image found."); return; }

    // Constants.

    // ---

    const CS_REF = +CoordinateSpaces.parentCoordinates;

    const CS_INN = +CoordinateSpaces.innerCoordinates;

    const CS_PBD = +CoordinateSpaces.pasteboardCoordinates;

    // ---

    const BB_VIS = +BoundingBoxLimits.OUTER_STROKE_BOUNDS;

    // ---

    const WS_SCA = +WhenScalingOptions.adjustScalingPercentage;

    const WS_RSZ = +WhenScalingOptions.applyToContent;

    // ---

    const MC_SCA = +MatrixContent.scaleValues;

    // Visible box center in *pasteboard* coordinates (because

    // we want that location to remain invariant.)

    // ---

    orig = p.resolve([AnchorPoint.centerAnchor, BB_VIS, CS_INN], CS_PBD)[0];

   

    // Matrix of `p` relative to its parent space--i.e, affine map.

    // (The whole purpose of `mx` is to backup scaling factors.)

    // ---

    mx = p.transformValuesOf(CS_REF)[0];

    if( 1==mx.horizontalScaleFactor && 1==mx.verticalScaleFactor ) return;

    // 1. Reset `p` scaling to 100% relative to its parent space.

    //    (`adjustScalingPercentage` is temporarily required.)

    // ---

    t = +(pf=app.transformPreferences).whenScaling;

    t==WS_SCA ? ( t=0 ) : ( pf.whenScaling=WS_SCA );

    p.transform( CS_REF, orig, [1,0,0,1,0,0], MC_SCA );

    t && (pf.whenScaling=t);

   

    // 2. Recover the original size by applying `mx` scale values.

    //    (`applyToContent` is temporarily required.)

    // ---

    t ? (t=0) : ( pf.whenScaling=t=WS_RSZ );

    p.transform( CS_REF, orig, mx, MC_SCA );

    t && (pf.whenScaling=t);

}

// Test.

// ---

redefineScalingAs100(app.selection[0]);

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
People's Champ ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

app.selection[0].redefineScaling();

Have I misunderstood the question?

Ariel

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 ,
Aug 11, 2019 Aug 11, 2019

Copy link to clipboard

Copied

Hi Ariel,

I'm afraid you have perfectly understood the question …and we just weren't aware of the redefineScaling() method

As we say in French, “le ridicule ne tue pas !”

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 ,
Aug 12, 2019 Aug 12, 2019

Copy link to clipboard

Copied

LATEST

Thanks guys, thanks TᴀW. Working perfectly. You helped me a lot. Thanks.

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