Skip to main content
WIDSnonamer
Inspiring
August 10, 2022
Answered

Flip / Mirror / Reflect whole Artboard

  • August 10, 2022
  • 2 replies
  • 1546 views

Good day!
I was looking for a way to mirror everything in an artboard, keeping the artboard dimensions. In the past I used PlacedItem and did a .resize(-100,100) to mirror my placed item. My workflow changed and i wanted to mirror the Artboard before i export it as PDF. I looked around, but most solutions only mirror one selected element. Even if I group everything and try to mirror the GroupItem it will mirror according to the GroupItem dimensions and not according to the artboard. I will attach a Image of the original and the desired result. Thanks in advance!

 

This topic has been closed for replies.
Correct answer sttk3

Resize has an option to specify a reference point for the transformation called scaleAbout.

Transformation.DOCUMENTORIGIN to this, you can move the reference point to virtually any position in the document.

 

var doc = app.documents[0] ;

// calculate reference point for resize
var bounds = doc.artboards[doc.artboards.getActiveArtboardIndex()].artboardRect ;
var artboardCenter = [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2] ;

try {
  // store original DOCUMENTORIGIN
  var originalDocumentOrigin = doc.rulerOrigin ;
  
  // set DOCUMENTORIGIN to artboard center
  doc.rulerOrigin = artboardCenter ;
  
  // resize items with Transformation.DOCUMENTORIGIN as reference point
  var targetItems = doc.selection ;
  for(var i = 0, len = targetItems.length ; i < len ; i++) {
    targetItems[i].resize(-100, 100, true, true, true, true, false, Transformation.DOCUMENTORIGIN) ;
  }
} catch(e) {
  alert(e) ;
} finally {
  doc.rulerOrigin = originalDocumentOrigin ;
}

2 replies

sttk3Correct answer
Legend
August 11, 2022

Resize has an option to specify a reference point for the transformation called scaleAbout.

Transformation.DOCUMENTORIGIN to this, you can move the reference point to virtually any position in the document.

 

var doc = app.documents[0] ;

// calculate reference point for resize
var bounds = doc.artboards[doc.artboards.getActiveArtboardIndex()].artboardRect ;
var artboardCenter = [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2] ;

try {
  // store original DOCUMENTORIGIN
  var originalDocumentOrigin = doc.rulerOrigin ;
  
  // set DOCUMENTORIGIN to artboard center
  doc.rulerOrigin = artboardCenter ;
  
  // resize items with Transformation.DOCUMENTORIGIN as reference point
  var targetItems = doc.selection ;
  for(var i = 0, len = targetItems.length ; i < len ; i++) {
    targetItems[i].resize(-100, 100, true, true, true, true, false, Transformation.DOCUMENTORIGIN) ;
  }
} catch(e) {
  alert(e) ;
} finally {
  doc.rulerOrigin = originalDocumentOrigin ;
}
Sergey Osokin
Inspiring
August 12, 2022

That's an interesting idea. I think we could add automatic selection of artboard content.

// resize items with Transformation.DOCUMENTORIGIN as reference point
doc.selectObjectsOnActiveArtboard();
var targetItems = doc.selection;

 

femkeblanco
Legend
August 10, 2022

This is a basic idea:

var doc = app.activeDocument;
var temp = doc.pathItems.rectangle(0, 0, doc.width, doc.height);
app.executeMenuCommand("selectall");
app.executeMenuCommand("group");
app.selection[0].resize(-100,100);
app.executeMenuCommand("ungroup");
temp.remove();
Disposition_Dev
Legend
August 11, 2022

nailed it. simple. elegant. 

femkeblanco
Legend
August 11, 2022

@Disposition_Dev  Thanks.  A problem is that the "group" and "ungroup" menu commands move all items to one layer.