Script for reflecting selection on both axis?

Explorer ,
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

108

Likes

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

Adobe Community Professional , Mar 02, 2022 Mar 02, 2022
another similar way app.selection[0].resize(-100,-100);

Likes

Translate

Translate
Adobe Community Professional ,
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

Likes

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 ,
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!")
}

 

Likes

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 ,
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);

 

Likes

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

Copy link to clipboard

Copied

LATEST

another similar way

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

Likes

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