9 Replies Latest reply on Mar 23, 2013 7:52 AM by pixxxel schubser

    Moving objects jsx?

    leo nascimento

      Hello everybody. Is there any way to move a object using its width? ex: "move to left a box with 10cm(width) using this value (10cm)". But I want to capture the width of any selected object.

      Another thing: i want to select objects with same fillcolor and do something like: pathfinder>>add;

      Thanks for any answer.

      And sorry for my bad english.

        • 1. Re: Moving objects jsx?
          CarlosCanto Adobe Community Professional & MVP

          this takes care of moving the selection to the left

           

          // move selected object left its own width
          var idoc = app.activeDocument;
          var sel = idoc.selection[0];
          
          
          sel.left = sel.left-sel.width;
          

           

           

          ...and this takes care of adding the effect 'add' (granted you first apply it manually to a group, then drag this group to the Graphic Styles Palette, and name it 'add')

           

          ...so, select your objects of the same color and group them before running

           

          var idoc = app.activeDocument;
          
          var sel = idoc.selection[0];
          var addStyle = idoc.graphicStyles['add'];
          addStyle.applyTo (sel);
          
          • 2. Re: Moving objects jsx?
            leo nascimento Level 1

            Thanks, CarlosCanto.

            I will now include this code to my script.

            When I'm done, I will put your name to the credits.

            Thanks again.

            • 3. Re: Moving objects jsx?
              leo nascimento Level 1

              My mistake.

              I did write: "pathfinder>>add".

              But I want: "pathfinder>>Unite".

              My both paths are selected and I just want to unite them.

              Thanks.

              • 4. Re: Moving objects jsx?
                CarlosCanto Adobe Community Professional & MVP

                oh, ok, same principle...change 'add' with 'unite', then don't use the "add" effect, use "unite" in the path finder palette.

                • 5. Re: Moving objects jsx?
                  leo nascimento Level 1

                  Thank again, CarlosCanto.

                  My intentions is: flip an object and unite to other one without leaving the script.

                  I had search and did not find any way to unite two path using script.

                  The only thing I miss is to unite the paths.

                  The hole code:

                   

                  var myDocument = app.activeDocument;

                  var selectedObject = myDocument.selection;

                   

                  var doc=app.activeDocument;

                  var sel = doc.selection[0];

                   

                  for (c=doc.selection.length-1;c>-1;c--){

                        doc.selection[c].duplicate(doc, ElementPlacement.INSIDE );            //duplicates my path

                        }

                   

                  espelha();    the name of my duplicate function(Brazilian portuguese)

                   

                  function espelha(){

                  var doc = app.activeDocument;     //actual doc            

                  var s    = doc.selection;               //actual selection

                  var sl   = s.length; 

                  var p = app.getScaleMatrix(-100, 100);

                  for(var i = 0 ; i < sl; i++) s[i].transform(p);

                  sel.left = sel.left-sel.width+0.1;                                                                   //CarlosCanto code

                     }

                  leodesenhos-espelho-script-jsx.JPG

                  Thanks again for your attention.

                  • 6. Re: Moving objects jsx?
                    CarlosCanto Adobe Community Professional & MVP

                    CarlosCanto wrote:

                     

                    oh, ok, same principle...change 'add' with 'unite', then don't use the "add" effect, use "unite" in the path finder palette.

                     

                    ok, that is not completely true, it seems we can't use path finder commands as graphic styles, you'll have to stick to effects...but then, you'll have to expand appearance manually.

                     

                    you didn't do this

                     

                     

                    ...and this takes care of adding the effect 'add' (granted you first apply it manually to a group, then drag this group to the Graphic Styles Palette, and name it 'add')

                     

                    ...so, select your objects of the same color and group them before running

                     

                    var idoc = app.activeDocument;  

                    var sel = idoc.selection[0];

                    var addStyle = idoc.graphicStyles['add'];

                    addStyle.applyTo (sel);

                     

                     

                    Was this helpf

                     

                    1 person found this helpful
                    • 7. Re: Moving objects jsx?
                      Muppet Mark Level 5

                      What version of the app are you using…? Pathfinder functions are installed in the app's default actions set… In CS6 you can run these actions… You can also select and expand the apperance by executing a menu item… There is a new feature that allows you to message a plug-in looks interesting but I'll be shot if I can find an example… I don't have CS6 in my box of toys…

                      • 8. Re: Moving objects jsx?
                        leo nascimento Level 1

                        Ok Muppet Mark. My version is AI CS5. I made an action doing the same thing: reflect a copy and pathfinder>>Unite. The problem is: I have to open the 'transform each' dialog to make some settings: reflect X, check the left reference point and click COPY. I want to do it using a script without a dialog. Just a click on my script. The script reflecting, works fine, but "unite" don't work.  The action to reflect don't work(without a dialog), but the "unite" does. I know a could, after running my script, open the pathfinder>>unite, and is all done.    leodesenhos-transformeach.JPG leodesenhos-transformeach-result.JPGleodesenhos-transformeach-result-final.JPG

                        Thanks for all replies.

                        • 9. Re: Moving objects jsx?
                          pixxxel schubser Level 5

                          Okay,

                           

                          - create (manually) a graphicstyle with Transform-Effect (Reflect)

                           

                          try this:

                           

                          - apply this Effect to your path

                          - save as Illustrator8

                          flattenSaveOptions.compatibility = Compatibility.ILLUSTRATOR8;

                          flattenSaveOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;

                          - close and re-open your document

                          - use the aics_script "Join Reasonably.jsx"

                           

                          Have fun