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

Script for reflecting selection on both axis?

Participant ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

Hello,

I have been running into this problem a lot during my workflow. I often need to reflect a selection on both axis, and the only way to do it is to manually reflect it on one axis, and then go through the process again for the other.

Does anyone know of any script that could solve this issue for me?

TOPICS
Scripting

Views

179

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

Community Expert , Mar 02, 2022 Mar 02, 2022

another similar way

app.selection[0].resize(-100,-100);

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

You could create an action that does both quite easily, unless you specifically need a script.

Screenshot 2022-03-02 113911.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
Participant ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

I have actually managed to find a script that does this. Leaving the code here, as it may help someone else in the future:

mySelection = activeDocument.selection;
if (mySelection.length>0){
    var doc = app.activeDocument;                   //current document
    var s    = doc.selection;                              //current slection
    var sl   = s.length;                                     //number of selected objects
    var m  = app.getScaleMatrix(-100,-100);       //H flip matrix - feel free to change to (100,-100) for vertical flip, etc.
    for(var i = 0 ; i < sl; i++) s[i].transform(m); //for each selected element apply the flip matrix
    app.redraw();
}else{
    alert("Nothing selected!")
}
mySelection = activeDocument.selection;
if (mySelection.length>0){
    var doc = app.activeDocument; //current document
    var s    = doc.selection; //current slection
    var sl   = s.length; //number of selected objects
    var m  = app.getScaleMatrix(-100,-100); //H flip matrix 
    for(var i = 0 ; i < sl; i++) s[i].transform(m); //for each selected element apply the flip matrix
    app.redraw();
}else{
    alert("Nothing selected!")
}

 

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 ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

An alternative approach (you can choose reflecting around either the X or Y-axis by deleting the reciprocal of the two last lines):

 

// select item
var item = app.activeDocument.selection[0];
function reflectY(item) {
    var m = new Matrix();
    m.mValueA = -1;
    m.mValueB = 0;
    m.mValueC = 0;
    m.mValueD = 1;
    item.transform(m);
}
function reflectX(item) {
    var m = new Matrix();
    m.mValueA = 1;
    m.mValueB = 0;
    m.mValueC = 0;
    m.mValueD = -1;
    item.transform(m);
}
reflectY(item);
reflectX(item);

 

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 ,
Mar 02, 2022 Mar 02, 2022

Copy link to clipboard

Copied

LATEST

another similar way

app.selection[0].resize(-100,-100);

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