15 Replies Latest reply on Dec 30, 2015 7:01 PM by JJMack

    How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?

    DocH999

      Hi,

       

      I'm a beginner to scripting, using Visual Basic.

      I'm trying to use the Rotate() method to rotate an artLayer in Photoshop CS6.

      .Rotate(14.5) etc seems absolutely fine.

       

      BUT I want to be able to specify the center around which the rotation occurs, which is, I understand, governed by psAnchorPoint.

      The syntax for Rotate() is given in the VB Scripting Reference Manual as:

       

      Rotate(Angle  [, Anchor])

       

      My question is, how do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list? I've tried a lot of variations but none seems to be acceptable. Any thoughts anyone?

        • 1. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
          JJMack Most Valuable Participant

          Most likely a defined constant. Here what a javascript one looks like.  http://www.mouseprints.net/old/dpr/RotateLayerAbout.jsx

           

          from photoshop-cc-vbs-ref.pdf  page 158

          PsAnchorPosition 1 (psTopLeft)

          2 (psTopCenter)

          3 (psTopRight)

          4 (psMiddleLeft)

          5 (psMiddleCenter)

          6 (psMiddleRight)

          7 (psBottomLeft)

          8 (psBottomCenter)

          9 (psBottomRight)

          The point on the object that does not

          move when the object is rotated or

          resized.

          • 2. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
            c.pfaffenbichler Level 9

            You may want to consider switching to JavaScript, there are probably more VB users than AS users but still JavaScript seems to be the most popular language for Photoshop Scripting.

            • 3. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
              DocH999 Level 1

              Hi JJMack and thanks.

               

              Yes I understand than PsAnchorPosition can have values of psTopCenter etc, but I don't understand the syntax I need to use to set the value to PsAnchorPosition. I don't know where PsAnchorPosition sits in the hierarchy of classes etc. It's referred to in the object browser as an "enum", but I don't even understand how to operate with this kind of thing. It looks from the definiton that Rotate() can take 2 parameters, but if I include a rotation angle, followed by a comma followed by something, I get the error message "Cannot use parentheses when calling a Sub"

               

              I am really a beginner at this and finding it conceptually very tricky(having done a lot of procedural programming in the past). Any help would be appreciated, ideally a chunk of code with .rotate() with PsAnchorPosition being initialised (however that is done).

               

               

              Hi  c.pfaffenbichler and thanks.

               

              I did wonder which language to plump for but I felt more at home with VBS. Am beginning to wonder though...

              • 4. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                c.pfaffenbichler Level 9
                I felt more at home with VBS. Am beginning to wonder though...

                As a Mac user I am not familiar with VB but if you expect automating Photoshop tasks will be a longtime endeavour for you and have the time JavaScript may be worth looking into.

                There are plenty of JavaScript Scripts for Photoshop available and more people may be able to help and assist with problems.

                • 5. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                  JJMack Most Valuable Participant

                  Choose to use JavaScript then.  If you ever think you may want get into Web html applications and other applications that support scripting. Javascript is supported on many platforms not just Mac and Windows.  VBS is Windows only and Apple script is Mac only.... Many application that have scripting support support javascript like Browsers.

                   

                  Adobe Photshop has is own scripting support plug-in. That plugin supports javascript, Applescript and VBS.   Adobe Scriptlistener  Plug-in records both Javascript and VBS code for use with  Adobe's action manager support.  While the code is  not very readable you can compare the javascript and VBS code recorded to see some of the Adobe constants uses in  their scripting support for the two languages.

                   

                  I do not know javascript I just hack at it.  Most of my programming experience was 360 Assembler code  some PL1. Scripting was VM CMS EXEC and Rex.  I sure wish Rex would have been more widely ported to the PC world. Rex was PL1 like and designed to be very readable by humans. I have worked in or on many OS on different size machines and  seem many languages.  Some were designed for machine not humans.  Decoding or remembering  thins like, APL, Regular Expressions, using reverse polish notation. Well these are all but impossible for me.  So I just hack others code these days in retirement.  I find I can usually fine code that address my what I want to work on, on the web. While the code found may not be what I want I can hammer it to do what I want. I have hacked some Large script. However most of the script I done are small like the Hack I posted. Was a hack of a simple scripting tutorial I found on the web.  I removed a prompt added a dialog and some features.    I found the code to save the dialog setting in a thread here.  Found  Dialog Code in threads here as well.

                   

                  Search and use a hammer.  If your young learn javascript. I'm 75 I see no need to become proficient using javascript. I can not even type but I can peck at the keys.

                   

                  I started just hacking small scripts to be used in Actions I would create.  To add the logic I need in the action.  Action are easy for me where scripting is hard but needed to be able to automate Photoshop better then actions. Look at the scripts in my crafting actions packege.  Most at extreamly small and readable.   They are small simple utilites for action to do thins they can not do because they can not use logic.

                   

                  Crafting Actions Package  UPDATED Aug 10, 2014 Added Conditional Action steps to Action Palette Tips.
                  Contains

                  Example
                  Download

                  • 6. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                    DocH999 Level 1

                    Hi JJMack and thanks again.

                     

                    Well, I'm having problems. At least when I was experimenting with VB I could get a script to create a file with a layer and put some text on it and view it in CS6.

                     

                    But when trying to run a javascript file to do the same thing, it falls over at the very first non-comment line with the error "undefined is not an object".  Needless to say, I don't have a clue what I'm doing wrong and what I'm supposed to do. The java debug window shows "ExtendScript Toolkit CS6" in the drop-down menu near the top left of the screen, so I suppose Extendscript for CS 6 is at least present.

                     

                    Any thoughts? This is not going well... I'm 65, and was programming PDP8's with paper tape in the 70's, along with Fortran and later Pascal, but I don't know how to proceed with this.

                     

                    Anyway, a very late lunch beckons...

                     

                    All the best.

                    • 7. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                      c.pfaffenbichler Level 9

                      Could you post the JavaScript you are using?

                      At which line does the error occur?

                      • 8. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                        pixxxel schubser MVP & Adobe Community Professional

                        It's Javascript + AM-Code, but …

                        how about with transform

                        var xAnchor = 100;
                        var yAnchor = 200;
                        var Angle = 45;
                        var idTrnf = charIDToTypeID( "Trnf" );
                            var desc17 = new ActionDescriptor();
                            var idnull = charIDToTypeID( "null" );
                                var ref9 = new ActionReference();
                                var idLyr = charIDToTypeID( "Lyr " );
                                var idOrdn = charIDToTypeID( "Ordn" );
                                var idTrgt = charIDToTypeID( "Trgt" );
                                ref9.putEnumerated( idLyr, idOrdn, idTrgt );
                            desc17.putReference( idnull, ref9 );
                            var idFTcs = charIDToTypeID( "FTcs" );
                            var idQCSt = charIDToTypeID( "QCSt" );
                            var idQcsi = charIDToTypeID( "Qcsi" );
                            desc17.putEnumerated( idFTcs, idQCSt, idQcsi );
                            var idPstn = charIDToTypeID( "Pstn" );
                                var desc18 = new ActionDescriptor();
                                var idHrzn = charIDToTypeID( "Hrzn" );
                                var idPxl = charIDToTypeID( "#Pxl" );
                                desc18.putUnitDouble( idHrzn, idPxl, xAnchor);
                                var idVrtc = charIDToTypeID( "Vrtc" );
                                var idPxl = charIDToTypeID( "#Pxl" );
                                desc18.putUnitDouble( idVrtc, idPxl, yAnchor );
                            var idPnt = charIDToTypeID( "Pnt " );
                            desc17.putObject( idPstn, idPnt, desc18 );
                            var idOfst = charIDToTypeID( "Ofst" );
                                var desc19 = new ActionDescriptor();
                                var idHrzn = charIDToTypeID( "Hrzn" );
                                var idPxl = charIDToTypeID( "#Pxl" );
                                desc19.putUnitDouble( idHrzn, idPxl, 0.000000 );
                                var idVrtc = charIDToTypeID( "Vrtc" );
                                var idPxl = charIDToTypeID( "#Pxl" );
                                desc19.putUnitDouble( idVrtc, idPxl, 0.000000 );
                            var idOfst = charIDToTypeID( "Ofst" );
                            desc17.putObject( idOfst, idOfst, desc19 );
                            var idAngl = charIDToTypeID( "Angl" );
                            var idAng = charIDToTypeID( "#Ang" );
                            desc17.putUnitDouble( idAngl, idAng, Angle );
                            var idIntr = charIDToTypeID( "Intr" );
                            var idIntp = charIDToTypeID( "Intp" );
                            var idBcbc = charIDToTypeID( "Bcbc" );
                            desc17.putEnumerated( idIntr, idIntp, idBcbc );
                        executeAction( idTrnf, desc17, DialogModes.NO );
                        

                         

                        Have fun

                         

                        • 9. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                          JJMack Most Valuable Participant

                          I'll just repeat what I wrote before

                          Search for a working script the does something like you want to do written in JavaScript and not save in binary.

                           

                          Hammer on that code.

                           

                          I do not even use the "ExtendScript Toolkit " except for its object viewer to soon object fields names.  The debugger windows and other data windows cpntents jump around to much I find this very distracting. My mind does not cope well all seems to change at once.  Most of the time I just want to see the path through the script.  I know the changing data wimdows auto scrolling is ment to help for me its more distracting then helpful. I may try collasping the other windows and figure out the stepong icons.  Read the manual is so not me.

                           

                          Though I would like a debugger I could step through the script like the toolkit has. Now I simply add alerts to step through scripts act like break points to see how VARs are currently set.

                          • 10. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                            DocH999 Level 1

                            Demo.jpg

                             

                            Hi c.pfaffenbichler,

                             

                            The above screen capture shows what happens. The code is taken from the CS6 scripting guide. I don't know why it's falling over, as if I do a F7->Check Syntax it reports "no errors."  I''m pretty clueless about where to go with this.

                             

                            Thanks.

                            • 11. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                              c.pfaffenbichler Level 9

                              Either add

                              #target photoshop

                              at the beginning or select Photoshop as the target application instead of ExtendScript Toolkit (at the top of the window).

                              • 12. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                                JJMack Most Valuable Participant

                                As I wrote  the scriptisener code generated for the action manager is not very readable and like an action its a Photoshop step and every variable is set hared coded.   You need to change the hard coded set value and replace them with variables.  Not all just some need the replacement.  Above three hard code sets values were replaced with variables  named xAnchor, yAnchor and Angle.

                                 

                                Some users can clean up Action manager including c.pfaffenbichler better then his example example.  Normally making a JavaScript function.  In the script I posted I ripped off the same function an other user poster. I may have made a minor change or two.  I feel that code though the same is more readable so I'll extract that part. Still and an angle  a x point and a y point need to be passed.

                                 

                                function rotateAroundPosition(_angle,x,y) {

                                  var desc1 = new ActionDescriptor();

                                  var desc2 = new ActionDescriptor();

                                  var ref1 = new ActionReference();

                                  ref1.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

                                  desc1.putReference(charIDToTypeID('null'), ref1);

                                  desc1.putEnumerated(charIDToTypeID('FTcs'), charIDToTypeID('QCSt'), stringIDToTypeID("QCSIndependent"));

                                  desc2.putUnitDouble(charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), x);

                                  desc2.putUnitDouble(charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), y);

                                  desc1.putObject(charIDToTypeID('Pstn'), charIDToTypeID('Pnt '), desc2);

                                  desc1.putUnitDouble(charIDToTypeID('Angl'), charIDToTypeID('#Ang'), _angle);

                                  desc1.putEnumerated(charIDToTypeID('Intr'), charIDToTypeID('Intp'), charIDToTypeID('Bcbc'));

                                  executeAction(charIDToTypeID('Trnf'), desc1, DialogModes.NO);

                                }

                                 

                                 

                                 

                                The above function would be use in your main line code.  For example if you wanted to rotate the current layer 90 degrees around the document canvas center you would code something like

                                 

                                rotateAroundPosition(90,activeDocument.width/2,activeDocument.height/2)


                                The script in action 4 points 12 rotations about each

                                Capture.jpg

                                ringabout.gif

                                • 13. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                                  DocH999 Level 1

                                  Hi guys and thanks for all your help.

                                   

                                  Ok, so now I'm working in javascript, and my simple bit of code works fine. Adds text, rotates by so many degrees. BUT I can't seem to change the point of rotation, the anchor position. This seems to default to the middle of the thing being rotated, which isn't bad, but I'd still like to be able to set it explicitly.

                                   

                                  So I am left with the question, How do I set the value of AnchorPosition in Javascript? Or perhasp the question should be, How do I USE the value of anchorposition in Javascript? Can someone, anyone explain what I have to do to set the anchor position? It should be just a single line or perhaps two, shouldn't it, not yards and yards of code - thanks for the code examples, but I'm trying to achieve what I'm doing by using the anchor point.  Or possibly I just need to supply the second parameter in the method .rotate(), but I can't get it to accept a second parameter. Getting so frustrated with this.

                                  • 14. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                                    DocH999 Level 1

                                    Found it!

                                     

                                    Having written the text string to the contents property of a text item in an artLayer, I need to do a:

                                     

                                    artLayerRef.rotate(45,  AnchorPosition.TOPLEFT)       'or  .MIDDLECENTRE or whatever

                                     

                                    Phew!

                                     

                                    Thanks again!

                                    • 15. Re: How do I include a value for  Anchor / psAnchorPosition   in the Rotate parameter list?
                                      JJMack Most Valuable Participant

                                      Again my script http://www.mouseprints.net/old/dpr/RotateLayerAbout.jsx  using three x y color sampler points for rotation  with three  rotation around each point so 120 degrees between layer ate each point.

                                      Capture.jpg

                                      Five rotation around the text layer center..

                                      Capture.jpg

                                      Four Rotations around the text layer right center

                                      Capture.jpg,

                                      Four rotations around the document center.

                                      Capture.jpg