5 Replies Latest reply on Jul 7, 2014 12:18 PM by NichtNummer1

    Script to change what part of the image is shown

    NichtNummer1

      Hello,

       

      is it possible to script "scrolling" to a specific part on any image?

      For example, that the bottom right corner of the image is at the center of the view.

       

      I am fairly new to Photoshop scripting, and I did not find any way to change the main view while looking through the Javascript Reference and Scripting Guide (or did I miss it?).

      We are using Photoshop CS4.

       

      Thanks

        • 1. Re: Script to change what part of the image is shown
          c.pfaffenbichler Level 9

          Documents have a property called "center" that can be assessed via Action Manager code, I don’t know how to feed it back, though.

          Also I don’t think the Window’s dimensions are available, so it might be no use either way.

          // 2014, use it at your own risk;

          #target photoshop

          if (app.documents.length > 0) {

          var ref = new ActionReference();

          ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

          var docDesc = executeActionGet(ref);

          var theCenter = docDesc.getObjectValue (stringIDToTypeID("center"));

          checkDesc2(theCenter);

          };

          ////// based on code by michael l hale //////

          function checkDesc2 (theDesc) {

          var c = theDesc.count;

          var str = '';

          for(var i=0;i<c;i++){ //enumerate descriptor's keys

            str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';

            };

          alert("desc\n\n"+str);

          };

          ////// check //////

          function getValues (theDesc, theNumber) {

          switch (theDesc.getType(theDesc.getKey(theNumber))) {

          case DescValueType.BOOLEANTYPE:

          return theDesc.getBoolean(theDesc.getKey(theNumber));

          break;

          case DescValueType.CLASSTYPE:

          return theDesc.getClass(theDesc.getKey(theNumber));

          break;

          case DescValueType.DOUBLETYPE:

          return theDesc.getDouble(theDesc.getKey(theNumber));

          break;

          case DescValueType.ENUMERATEDTYPE:

          return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStr ingID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));

          break;

          case DescValueType.INTEGERTYPE:

          return theDesc.getInteger(theDesc.getKey(theNumber));

          break;

          case DescValueType.LISTTYPE:

          return theDesc.getList(theDesc.getKey(theNumber));

          break;

          case DescValueType.OBJECTTYPE:

          return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObject Type(theDesc.getKey(theNumber))));

          break;

          case DescValueType.REFERENCETYPE:

          return theDesc.getReference(theDesc.getKey(theNumber));

          break;

          case DescValueType.STRINGTYPE:

          return theDesc.getString(theDesc.getKey(theNumber));

          break;

          case DescValueType.UNITDOUBLE:

          return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUn itDoubleType(theDesc.getKey(theNumber))));

          break;

          default:

          break;

          };

          };

          • 2. Re: Script to change what part of the image is shown
            c.pfaffenbichler Level 9

            This is only peripherally connected to your issue

            Photoshop: Save/Reopen projects/collections of files and save window positions

            so maybe you should start a proper feature request over Photoshop Family Customer Community

            • 3. Re: Script to change what part of the image is shown
              NichtNummer1 Level 1

              Thank you!

               

              That is quite a lot of code

              How do you know what the strings you have to pass to the ActionReference have to be?

               

              Also, I think ActionReference is not available in CS4? This might be a good opportunity to persuade my client to upgrade...

               

              I will take a look at the things you provided and hopefully be able to get this working. Is it OK if I wait until then to mark some answer as correct?

               

              Cheers

              • 4. Re: Script to change what part of the image is shown
                c.pfaffenbichler Level 9

                I will take a look at the things you provided and hopefully be able to get this working. Is it OK if I wait until then to mark some answer as correct?

                My answers do not solve your issue and I cannot definitely state whether it’s even possible, so marking them as correct would be an exaggeration in any case.

                Nice of you to give this some thought, but you need not use the the correct marking.

                 

                How do you know what the strings you have to pass to the ActionReference have to be?

                Well, I’m not really comfortable with AM code myself, so I don’t know either for this case or even if it’s possible.

                And like I said the Window’s dimensions do not seem to be accessible through Scripting, so the whole issue may be moot.

                • 5. Re: Script to change what part of the image is shown
                  NichtNummer1 Level 1

                  You are right. After looking through many posts on ActionManager code online, it seems changing just the view is not possible, even using ActionManager.

                   

                  As a workaround, I implemented a script that fits the image on screen, zooms in and moves the image half off-screen so that the edge is at the center. Ugly hack, I know, but the customer is satisfied so whatever

                   

                  Thanks for pointing me to ActionManager, it was quite an interesting topic to look at.