Skip to main content
Participating Frequently
December 10, 2008
Answered

How to reflect in script?

  • December 10, 2008
  • 3 replies
  • 4395 views
Hi,

I want the equivalent of choosing Object > Transform > Reflect, across the Vertical axis. How would I do this with JavaScript?

Thanks,

Max
This topic has been closed for replies.
Correct answer Ten A

Try below code:

function applyTM(tg, a, b, c, d) {

  var tm = new Matrix();

  tm.mValueA = a;

  tm.mValueB = b;

  tm.mValueC = c;

  tm.mValueD = d;

  tm.mValueTX = 0;

  tm.mValueTY = 0;

  tg.transform(tm,true,true,true,true,1);

  app.redraw();

  }

applyTM (app.activeDocument.selection[0],-1,0,0,1);

if you want to transform horizontal:

applyTM (app.activeDocument.selection[0],1,0,0,-1);

Ten

3 replies

Participant
October 26, 2023

var totalMatrix = app.getScaleMatrix(-100, 100); // Cria a matriz de escala

var layer = app.activeDocument.activeLayer; // Obtém a camada ativa

for (var i = 0; i < layer.pageItems.length; i++) {
// Itera por todos os itens na camada
var currentItem = layer.pageItems[i];

// Verifica se o nome do item é "verso" antes de aplicar a matriz de escala
if (currentItem.name === "verso") {
currentItem.transform(totalMatrix);
}
}

This code works!

Participant
October 26, 2023

var totalMatrix = app.getScaleMatrix(-100, 100); // Cria a matriz de escala

var layer = app.activeDocument.activeLayer; // Obtém a camada ativa

for (var i = 0; i < layer.pageItems.length; i++) {
        // Itera por todos os itens na camada
         var currentItem = layer.pageItems[i];

 

        // Verifica se o nome do item é "verso" antes de aplicar a matriz de escala
        if (currentItem.name === "verso") {
              currentItem.transform(totalMatrix);

       }
}

Participant
October 26, 2023

var totalMatrix = app.getScaleMatrix(-100, 100); // Create the scale matrix

 

var layer = app.activeDocument.activeLayer; // Get the active layer

 

for (var i = 0; i < layer.pageItems.length; i++) {
        // Iterate through all items in the layer
        var currentItem = layer.pageItems[i];

 

        // Check if the item's name is "verso" before applying the scale matrix
        if (currentItem.name === "verso") {
                currentItem.transform(totalMatrix);
        }
}

But u got change the name of the object to "verso" and the layers to "Camada 1"

BaptistaCG
Participant
January 14, 2015

Hi,

There's a script created by our friend Gustavo Del Vechio (Reflex 1.0), he made a tool for that, follow your site:

Scripts (English) | Núcleo do Illustrator

Thanks again Gustavo!

Silly-V
Legend
February 27, 2018

No reason for this comment other than to point that, it contains legends of our industry (not talking about myself of course)

Known Participant
December 15, 2008
Max this is AppleScript but should at least give you a clue to using the transform object and matrix values. You should be able to translate to JavaScript.

tell application "Adobe Illustrator"
activate
set Doc_Ref to the current document
tell Doc_Ref
set Group_XY to position of group item 1 of layer 1
set RefVert_Matrix to ¬
{class:matrix, mvalue_a:-1.0, mvalue_b:0.0, mvalue_c:0.0, mvalue_d:1.0, mvalue_tx:0.0, mvalue_ty:0.0}
transform group item 1 of layer 1 using RefVert_Matrix about center
set position of group item 1 of layer 1 to Group_XY
end tell
end tell

BTW when ever I have used this it always appears to move very slightly so check your bounds before and after.
Muhammad_eloc
Known Participant
December 30, 2014

hello,

are there any way to do that in java script not apple

Object > Transform > Reflect, across the Vertical axis

Ten A
Community Expert
Ten ACommunity ExpertCorrect answer
Community Expert
January 13, 2015

Try below code:

function applyTM(tg, a, b, c, d) {

  var tm = new Matrix();

  tm.mValueA = a;

  tm.mValueB = b;

  tm.mValueC = c;

  tm.mValueD = d;

  tm.mValueTX = 0;

  tm.mValueTY = 0;

  tg.transform(tm,true,true,true,true,1);

  app.redraw();

  }

applyTM (app.activeDocument.selection[0],-1,0,0,1);

if you want to transform horizontal:

applyTM (app.activeDocument.selection[0],1,0,0,-1);

Ten