12 Replies Latest reply on Apr 28, 2016 1:48 AM by Suzan.V

    Transform Each

    Suzan.V

      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

       

        • 1. Re: Transform Each
          Ten A Adobe Community Professional

          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[i]);
          
          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);
            }
          
          • 2. Re: Transform Each
            CarlosCanto Adobe Community Professional & MVP

            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[i]

                 yourFunction(item);

            }

             

            function yourFunction (item) {

                 do something to item

            }

            • 3. Re: Transform Each
              Silly-V Adobe Community Professional

              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[i], { horizontal : true });
                }
              };
              test();
              
              • 4. Re: Transform Each
                Suzan.V Level 1

                Dear Carlos,

                 

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

                6.png

                • 5. Re: Transform Each
                  Suzan.V Level 1

                  Dear Ten,

                   

                  maybe your code helps me a little, thanks a lot

                  • 6. Re: Transform Each
                    Suzan.V Level 1

                    Dear Silly,

                     

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

                    • 7. Re: Transform Each
                      Suzan.V Level 1

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

                       

                      4.png

                      • 8. Re: Transform Each
                        Silly-V Adobe Community Professional

                        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[i], { horizontal : true }); 
                        15.   } 
                        16. }; 
                        17. test(); 
                        • 9. Re: Transform Each
                          Silly-V Adobe Community Professional

                          To select the text objects:

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

                          1 person found this helpful
                          • 10. Re: Transform Each
                            CarlosCanto Adobe Community Professional & MVP

                            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.

                            • 11. Re: Transform Each
                              Ten A Adobe Community Professional

                              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();
                              }())
                              
                              1 person found this helpful
                              • 12. Re: Transform Each
                                Suzan.V Level 1

                                Dear Ten A ,

                                 

                                many thanks to you it works like magic

                                 

                                your help is highly apprecaited

                                 

                                Thanks dear