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

Transform Each

Participant ,
Apr 25, 2016 Apr 25, 2016

Hi all,

i'm working on a script and final step is missing, i just want to know Transform each function code on JavaScript, or at least i want to create a code can do a shortcut like (Alt+Ctrl+Shift+D)

Object > Transform > Transform Each with Reflect X and Center point position

image.png

7.png

is it possible??

Thanks a lot

TOPICS
Scripting
7.0K
Translate
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 , Apr 27, 2016 Apr 27, 2016

Try it:

(function(){

  var str = "";

  var act = "/version 3 /name [ 4 73657431]"

  +"/isOpen 1 /actionCount 1"

  +"/action-1 {/name [ 7 616374696f6e31]"

  +"/keyIndex 0 /colorIndex 0/isOpen 1 /eventCount 1"

  +"/event-1 {/useRulersIn1stQuadrant 0 /internalName (ai_plugin_TransformEach)"

  +"/isOpen 0 /isOn 1 /hasDialog 1 /showDialog 0 /parameterCount 13"

  +"/parameter-1 {/key 1936224890 /showInPalette 4294967295 /type (unit real)"

  +"/value 100.0 /unit 592474723}"

  +"/parameter-2 {/key 1937142388 /show

...
Translate
Adobe
Community Expert ,
Apr 25, 2016 Apr 25, 2016

You can use actions and call from Javascript using doScript method. However, Transform Matrix is simple way to reflect objects. You can reference below function:

var tg = app.selection;

for(var i=0;i<tg.length;i++) applyReflect(tg);

function applyReflect(tgt){

  var tm = new Matrix();

  tm.mValueA = -1;

  tm.mValueB = 0;

  tm.mValueC = 0;

  tm.mValueD = 1;

  tm.mValueTX = 0;

  tm.mValueTY = 0;

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

  }

Translate
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 ,
Apr 26, 2016 Apr 26, 2016

Dear Ten,

maybe your code helps me a little, thanks a lot

Translate
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 ,
Apr 27, 2016 Apr 27, 2016

Try it:

(function(){

  var str = "";

  var act = "/version 3 /name [ 4 73657431]"

  +"/isOpen 1 /actionCount 1"

  +"/action-1 {/name [ 7 616374696f6e31]"

  +"/keyIndex 0 /colorIndex 0/isOpen 1 /eventCount 1"

  +"/event-1 {/useRulersIn1stQuadrant 0 /internalName (ai_plugin_TransformEach)"

  +"/isOpen 0 /isOn 1 /hasDialog 1 /showDialog 0 /parameterCount 13"

  +"/parameter-1 {/key 1936224890 /showInPalette 4294967295 /type (unit real)"

  +"/value 100.0 /unit 592474723}"

  +"/parameter-2 {/key 1937142388 /showInPalette 4294967295 /type (unit real) /value 100.0 /unit 592474723}"

  +"/parameter-3 {/key 1835561594 /showInPalette 4294967295 /type (unit real) /value 0.0 /unit 592476268}"

  +"/parameter-4 {/key 1836479092 /showInPalette 4294967295 /type (unit real) /value 0.0 /unit 592476268}"

  +"/parameter-5 {/key 1634625388 /showInPalette 4294967295 /type (unit real) /value 0.0 /unit 591490663}"

  +"/parameter-6 {/key 1668247673 /showInPalette 4294967295 /type (boolean) /value 0}"

  +"/parameter-7 {/key 1919837293 /showInPalette 4294967295 /type (boolean) /value 0}"

  +"/parameter-8 {/key 1818848869 /showInPalette 4294967295 /type (boolean) /value 1}"

  +"/parameter-9 {/key 1868720756 /showInPalette 4294967295 /type (boolean) /value 1}"

  +"/parameter-10 {/key 1885434990 /showInPalette 4294967295 /type (boolean) /value 0}"

  +"/parameter-11 {/key 1919247980 /showInPalette 4294967295 /type (boolean) /value 1}" //vertical

  +"/parameter-12 {/key 1919247993 /showInPalette 4294967295 /type (boolean) /value 0}" //horizontal

  +"/parameter-13 {/key 1885957744 /showInPalette 4294967295 /type (enumerated) /name [ 6 e4b8ade5bf83]"

  +"/value 4}}}";

  var tmp = File(Folder.desktop + "/.set1.aia"); 

  tmp.open('w'); 

  tmp.write(act);

  tmp.close();

  app.loadAction(tmp);

  app.doScript("action1", "set1", false); 

  app.unloadAction("set1","");

  tmp.remove();

}())

Translate
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 ,
Apr 28, 2016 Apr 28, 2016
LATEST

Dear Ten A ,

many thanks to you it works like magic

your help is highly apprecaited

Thanks dear

Translate
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 ,
Apr 25, 2016 Apr 25, 2016

there's no transform each, but you can make a rudimentary version by looping thru your objects and applying your function to each

// pseudo-code

for (var i=0; i<numberOfItems; i++) {

     item = items

     yourFunction(item);

}

function yourFunction (item) {

     do something to item

}

Translate
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
Valorous Hero ,
Apr 25, 2016 Apr 25, 2016

Here I come with this Easter Egg: CarlosCanto​ you actually were the Prometheus this time, you got us the applyEffect() functionality from Mt. Olympus, thank you very much: Re: PageItem.applyEffect(LiveEffectXML)

So,  you can actually have transform each with the Transform Effect. (Cannot be done on group, has to be individually applied to each item, could be immediately expanded though, but is best mass-applied to individual objects via new graphic style & application of that style (again via action?))

But, that's totally almost beside the point as scaling each object with a negative width is what I'd usually do.

#target illustrator-19

function test(){

  function reflectObject(art, reflectionOptionsObj){

   var opt = reflectionOptionsObj;

   if(opt.horizontal){

     art.resize(-100, 100);

   }

   if(opt.vertical){

     art.resize(100, -100);

   }

  };

  var doc = app.activeDocument;

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

  reflectObject(doc.compoundPathItems, { horizontal : true });

  }

};

test();

Translate
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 ,
Apr 26, 2016 Apr 26, 2016

Dear Silly,

it seems that i can't see any change after i run your code, more hints please

Translate
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 ,
Apr 26, 2016 Apr 26, 2016

i was wandering too what is the right code to select all text objects only??

4.png

Translate
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
Valorous Hero ,
Apr 26, 2016 Apr 26, 2016

To select the text objects:

app.executeMenuCommand("Text Objects menu item");

Translate
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
Valorous Hero ,
Apr 26, 2016 Apr 26, 2016

Oh yeah, that code works on compoundPathItems because I took a bunch of text and expanded it to get some instant practice shapes. You could make it work on groupItems or pageItems, etc.

Here it is for working on a selection (must have a selection first)

  1. #target illustrator-19 
  2. function test(){ 
  3.   function reflectObject(art, reflectionOptionsObj){ 
  4.    var opt = reflectionOptionsObj; 
  5.    if(opt.horizontal){ 
  6.      art.resize(-100, 100); 
  7.    } 
  8.    if(opt.vertical){ 
  9.      art.resize(100, -100); 
  10.    } 
  11.   }; 
  12.   var doc = app.activeDocument; 
  13.   for (var i = 0; i < doc.selection.length; i++) { 
  14.   reflectObject(doc.selection, { horizontal : true }); 
  15.   } 
  16. }; 
  17. test(); 
Translate
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 ,
Apr 26, 2016 Apr 26, 2016

Dear Carlos,

actually there is transform each action and i have posted a screenshot proving that and I'm using (CC) version

6.png

Translate
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 ,
Apr 26, 2016 Apr 26, 2016

Suzan.V wrote:

Dear Carlos,

actually there is transform each action and i have posted a screenshot proving that and I'm using (CC) version

6.png

I meant, it's not available to javascript.

Translate
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