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

Script to Scale selected content graphic frame Data merge

Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Hi

I am preparing a date merge process , I want to scale X and Y For each content graphic frame of 5 graphic frames by a certain presentage different from other graphic frames

Is there are a script to do that Automatically 

TOPICS
Scripting

Views

716

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 3 Correct answers

Enthusiast , Jul 23, 2023 Jul 23, 2023

Hi @r28071715i111 , here is a version that will scale in percentage :

/**
 * Apply Scale to graphics with a "Scale" script label.
 * eg. if label is "s:10", then the graphic will be scaled to 10%
 * @Originally authored by m1b for roation version 
 * Updated Scale Version By M.Hasanin
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
 */
function main() {

    var doc = app.activeDocument,
        images = doc.a
...

Votes

Translate

Translate
Enthusiast , Jul 23, 2023 Jul 23, 2023

hi @r28071715i111 , here is another version as you asked me in private message that will scale and rotate in same time :

/**
 * Apply Scale and Rotation to graphics script labels
 * eg. if label is "r:30 s:10", then the graphic will be rotated to 30 degree and scaled to 10%
 * @Originally authored by m1b for rotation version 
 * Updated Mixed Rotation and Scale Version By M.Hasanin
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data
...

Votes

Translate

Translate
Community Expert , Jul 23, 2023 Jul 23, 2023

Hi @M.Hasanin, thank you for doing this, very well done. Your scripting is going very well. As it happened (one minute later than you!) I was about to post a version of my same script that handled scaling also. I will post it here so you may see if I did anything differently.

- Mark

/**
 * Apply scale and rotation to graphics according to their script label.
 * eg. if label is "scale: 110, rotate: 15" then the graphic will be
 * scaled to 110% and rotated to 15° counter-clockwise.
 * @author m1b
...

Votes

Translate

Translate
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Any Help here

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 ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

It's a simple modification of the other script you've already received on the other thread about rotating objects  - I'm not JS guy so can't help you but please ask there.

 

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
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Thanks for your reply

I hope one one of js can help me in this script

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
New Here ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Hello,

Yes, you can automate the process of scaling X and Y for each content graphic frame using a script. However, the exact script you need will depend on the software or website programming language you are using to work with these graphic frames.

If you are working with a graphic design software like Adobe Illustrator or Photoshop, you might be able to use their built-in scripting capabilities. Both applications support scripting using JavaScript. You can write a script that iterates through the graphic frames and applies the desired scaling percentage to each one.

Here's a general outline of how the script might work in JavaScript for Adobe Illustrator:

  1. Get a reference to the graphic frames you want to scale.
  2. Iterate through each graphic frame.
  3. Apply the scaling percentage to the X and Y properties of the frame.

For Adobe Photoshop, the scripting process would be similar, but you would use Photoshop's JavaScript API to manipulate the graphic frames.

If you are working with a different software or a programming language, the approach might vary. Some graphic design software might have their own scripting languages or APIs to achieve similar results.

If you provide more details about the software you are using or the specific programming language you want to work with, I can try to help you with a more specific script example.

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
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Thanks For Your great reply

I want script for Adobe indesign only

Not illustrator and photoshop

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 ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

As I've already said - base of the script has been already created - just needs small modification:

https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-dat...

 

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
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Iam not a js , can't make modifcation for the script

If you can make this small modifcation please do it

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 ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

My reply wasn't to your post. 

 

I'll try. 

 

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
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Thanks For your reply

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 ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

 

/**
 * Apply rotation to graphics with a "rotate" script label.
 * eg. if label is "rotate: 15", then the graphic will be
 * rotated by 15° counter-clockwise.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
 * 
 * @MODIFIED Robert Tkaczyk
 * Scale graphics with a "scale" script label.
 * eg. if label is "scale:50", - no space after ":" - then the graphic will be
 * scaled by 50%.
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-scale-selected-content-graphic-frame-data-merge/td-p/13956297
 */
function main() {

    var doc = app.activeDocument,
//        tm = app.transformationMatrices.add({ counterclockwiseRotationAngle: 0 }),
        tm = app.transformationMatrices.add({ horizontalScaleFactor: 1, verticalScaleFactor: 1 }),
        images = doc.allGraphics,
//        matcher = /^rotate:(-?\d+\.?\d*)/i,
        matcher = /^scale:(-?\d+\.?\d*)/i,
        label,
        value;

    for (var i = 0; i < images.length; i++) {

        label = images[i].label || images[i].parent.label;

        if (!label)
            continue;

        value = label.match(matcher);

        if (!value
            || value.length < 2
            || isNaN(value = Number(value[1]))
        )
            continue;

        images[i].transform(
            CoordinateSpaces.pasteboardCoordinates,
            AnchorPoint.centerAnchor,
            tm.scaleMatrix(value/100 ,value/100 ),
        );
//            tm.rotateMatrix(-images[i].absoluteRotationAngle + value),

    }

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Rotate Graphics');

 

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
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Thanks For your Reply

But When I tried it , Scaling Presentage is not correct

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 ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Like I've said - I'm not JS guy. 

Version with setting scale directly - instead of using matrices - is much better. 

 

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
Engaged ,
Jul 25, 2023 Jul 25, 2023

Copy link to clipboard

Copied

LATEST

Thanks for your effort and concern

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
Enthusiast ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Hi @r28071715i111 , here is a version that will scale in percentage :

/**
 * Apply Scale to graphics with a "Scale" script label.
 * eg. if label is "s:10", then the graphic will be scaled to 10%
 * @Originally authored by m1b for roation version 
 * Updated Scale Version By M.Hasanin
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
 */
function main() {

    var doc = app.activeDocument,
        images = doc.allGraphics,
        matcher = /^s:(-?\d+\.?\d*)/i,
        label,
        value;

    for (var i = 0; i < images.length; i++) {

        label = images[i].label || images[i].parent.label;

        if (!label)
            continue;

        value = label.match(matcher);

        if (!value
            || value.length < 2
            || isNaN(value = Number(value[1]))
        )
            continue;

        images[i].horizontalScale =  images[i].verticalScale = value;

    }

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Scale Graphics Percent');
Best
Mohammad Hasanin

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
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Thanks For Great effort Mr Mohammad Hasanin

I tried it and worked like a charm

very very 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
Enthusiast ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

hi @r28071715i111 , here is another version as you asked me in private message that will scale and rotate in same time :

/**
 * Apply Scale and Rotation to graphics script labels
 * eg. if label is "r:30 s:10", then the graphic will be rotated to 30 degree and scaled to 10%
 * @Originally authored by m1b for rotation version 
 * Updated Mixed Rotation and Scale Version By M.Hasanin
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
 */

function main() {

    var doc = app.activeDocument,
        tm = app.transformationMatrices.add({ counterclockwiseRotationAngle: 0 }),
        images = doc.allGraphics,
        matcher = /^r:(-?\d+\.?\d*)\s+s:(-?\d+\.?\d*)/i, // match both values in one regex (Rotation and Scale with Space)
        label,
        value1,
        value2;

    for (var i = 0; i < images.length; i++) {

        label = images[i].label || images[i].parent.label;

        if (!label)
            continue;

        var matches = label.match(matcher);

        if (!matches || matches.length < 3) // check for both values
            continue;

        value1 = Number(matches[1]); // set value1 to the first match Rotate
        value2 = Number(matches[2]); // set value2 to the second match Scale Percentage


        images[i].transform( //Roatation
            CoordinateSpaces.pasteboardCoordinates,
            AnchorPoint.centerAnchor,
            tm.rotateMatrix(-images[i].absoluteRotationAngle + value1),
        );
        
        images[i].horizontalScale = images[i].verticalScale = value2; //Scale Percentage

    }

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Scale and Rotate Graphics');
Best
Mohammad Hasanin

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
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Thanks For Great effort Mr Mohammad Hasanin

I also tried it and worked like a charm

That script that I need definitly

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
Enthusiast ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

@r28071715i111  

You are welcome

Best
Mohammad Hasanin

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 ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Hi @M.Hasanin, thank you for doing this, very well done. Your scripting is going very well. As it happened (one minute later than you!) I was about to post a version of my same script that handled scaling also. I will post it here so you may see if I did anything differently.

- Mark

/**
 * Apply scale and rotation to graphics according to their script label.
 * eg. if label is "scale: 110, rotate: 15" then the graphic will be
 * scaled to 110% and rotated to 15° counter-clockwise.
 * @author m1b
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-rotate-selected-image-inside-frame-data-merge/m-p/13955151
 */
function main() {

    var doc = app.activeDocument,
        images = doc.allGraphics,
        rotationMatcher = /\brotate:\s*(-?\d+\.?\d*)/i,
        scaleMatcher = /\bscale:\s*(\d+\.?\d*)/i,
        label,
        scale,
        rotation;

    for (var i = 0; i < images.length; i++) {

        label = images[i].label || images[i].parent.label;

        if (!label)
            continue;

        rotation = label.match(rotationMatcher);
        scale = label.match(scaleMatcher);

        if (
            !rotation
            || rotation.length < 2
            || isNaN(rotation = Number(rotation[1]))
        )
            rotation = undefined;
        else
            rotation -= images[i].absoluteRotationAngle;

        if (
            !scale
            || scale.length < 2
            || isNaN(scale = Number(scale[1]))
        )
            scale = undefined;
        else
            scale = scale / images[i].absoluteHorizontalScale;

        if (!rotation && !scale)
            continue;

        var tm = app.transformationMatrices.add({
            counterclockwiseRotationAngle: rotation,
            horizontalScaleFactor: scale,
            verticalScaleFactor: scale,
        });

        images[i].transform(
            CoordinateSpaces.pasteboardCoordinates,
            AnchorPoint.centerAnchor,
            tm,
        );

    }

};

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Transform Graphics');

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
Enthusiast ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Hi @m1b , your script is excellent also, thank you, very briliant idea from its base, cheers

Best
Mohammad Hasanin

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
Engaged ,
Jul 23, 2023 Jul 23, 2023

Copy link to clipboard

Copied

Hi @m1b

Also Your Script is very very good 

Big Great thanks For Your Effort and concern

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