7 Replies Latest reply on Jun 30, 2009 2:40 AM by [Jongware]

    ID CS3: How to place a rotated text box against the side of a photo box?

    NYJack

      ID CS3: How to place a rotated text box against the side of a photo box?

       

      In ID CS3, I painstakingly place photo credits alongside their respective photos many times a day and could use the extra time for too many other things, so I’m thinking, is a script possible for this:

       

      I’ll have a photo to import, after which I need to place a rotated photo credit on the bottom-left side of the photo as follows:

       

      Text box 8 picas wide; 12 pts high;

       

      Text left-aligned in box: Photo Joe Klein

       

      Text attributes: Helvetica Medium 5 pts; baseline shifted -6; tracking -15; Optical kerning;

       

      The 90-degrees-rotated text box is then placed with the 8-pica-wide side against the left wall of the photo box, then moved downward 1 pt.

       

      May we all be blessed with . . . more time.

        • 1. Re: ID CS3: How to place a rotated text box against the side of a photo box?
          [Jongware] Most Valuable Participant

          Here you go. A fun exercise in finding out the right parameter for various things.

           

          var photo = app.selection[0];
          if (photo == undefined || photo.constructor.name != "Rectangle")
          {
           alert ("Please select a picture");
          } else
          {
           var theText = prompt ("Text", "Photo Joe Klein", "Enter straddle line");
           if (theText != null)
           {
            var oldHorizontalUnits = app.activeDocument.viewPreferences.horizontalMeasurementUnits;
            var oldVerticalUnits = app.activeDocument.viewPreferences.verticalMeasurementUnits;
            app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
            app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
            xpos = photo.geometricBounds[2];
            ypos = photo.geometricBounds[3];
            frame = app.activeDocument.textFrames.add (undefined, undefined, undefined, {absoluteRotationAngle:90} );
            frame.geometricBounds = [xpos+1,ypos, xpos-96, ypos+12];
            app.activeDocument.viewPreferences.horizontalMeasurementUnits = oldHorizontalUnits;
            app.activeDocument.viewPreferences.verticalMeasurementUnits = oldVerticalUnits;
            frame.parentStory.appliedFont = app.fonts.item("Helvetica\tMedium");
            frame.parentStory.appliedFontSize = 5;
            frame.parentStory.baselineShift = -6;
            frame.parentStory.tracking = -15;
            frame.parentStory.kerningMethod = "Optical";
            frame.parentStory.justification = Justification.LEFT_ALIGN;
            frame.contents = theText;
           }
          }
          


          Tested on CS; the rotation changed a bit with CS2 or CS3, so it might not work right out of the box (and you'll have to wait until Monday for me, or s/o else to fix it).

          If your by-line is always the same, you could remove the 'prompt' statement and replace it with a simple assignment:

           

          theText = "Photo Joe Klein";
          • 2. Re: ID CS3: How to place a rotated text box against the side of a photo box?
            NYJack Level 1

            Elegant, simple and fast. Beautiful.

             

            I took out the reference to 5-pt text size as it was sticking there and made a few changes (bringing it to the bottom left side) and the amount of movement down (to .4 pts). I'm not sure of the syntax regarding the 5-pt text size.

             

            This is what I see works just super (after I manually change size to 5 pts):

             

            var photo = app.selection[0];

            if (photo == undefined || photo.constructor.name != "Rectangle")

            {

            alert ("Please select a picture");

            } else

            {

            var theText = prompt ("Text", "Photo Joe Klein", "Enter straddle line");

            if (theText != null)

            {

              var oldHorizontalUnits = app.activeDocument.viewPreferences.horizontalMeasurementUnits;

              var oldVerticalUnits = app.activeDocument.viewPreferences.verticalMeasurementUnits;

              app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;

              app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;

              xpos = photo.geometricBounds[2];

              ypos = photo.geometricBounds[1];

              frame = app.activeDocument.textFrames.add (undefined, undefined, undefined, {absoluteRotationAngle:90} );

              frame.geometricBounds = [xpos+.4,ypos, xpos-96, ypos-12];

              app.activeDocument.viewPreferences.horizontalMeasurementUnits = oldHorizontalUnits;

              app.activeDocument.viewPreferences.verticalMeasurementUnits = oldVerticalUnits;

              frame.parentStory.appliedFont = app.fonts.item("Helvetica\tMedium");

              frame.parentStory.baselineShift = -6;

              frame.parentStory.tracking = -15;

              frame.parentStory.kerningMethod = "Optical";

              frame.parentStory.justification = Justification.LEFT_ALIGN;

              frame.contents = theText;

            }

            }

             

             

             

            • 3. Re: ID CS3: How to place a rotated text box against the side of a photo box?
              [Jongware] Most Valuable Participant

              The left side, eh? Sorry :-) But you changed it the correct way, it seems.

               

              I don't get what's wrong with the 5 pt text size. The line

               

              frame.parentStory.appliedFontSize = 5;

               

              applies it to new text in the frame. If you take that out, the text size is no longer changed from the default. (Well worth underlining that.) Every new text frame gets its default settings from the ones in your character panel with nothing selected. If you change that default from what it is now (perhaps 5 pt?) to, say, 12 pt, the text in any new sidelines will be at 12 pt -- because that's the size that's going to be there when the frame is created, and it doesn't get overridden in the script.

               

              I'm not sure of the syntax regarding the 5-pt text size

               

              It's as easy as the line above. Simply change the '5' to whatever you need. By the way, I changed the measurement units to points for correctly positioning the new text frame, but for text size this is not necessary -- it's always measured in points.

              • 4. Re: ID CS3: How to place a rotated text box against the side of a photo box?
                NYJack Level 1

                I still get the following error message when I put back in the line pertaining to font size:

                 

                 

                JavaScript Error!

                 

                Error Number: 55

                Error String: Object does not support the property or method ‘appliedFontSize’

                Line: 25

                Source: frame.parentStory.appliedFontSize = 5;

                • 5. Re: ID CS3: How to place a rotated text box against the side of a photo box?
                  Dave Saunders Level 4

                  The property name is pointSize, not appliedFontSize.

                   

                  Dave

                  • 6. Re: ID CS3: How to place a rotated text box against the side of a photo box?
                    NYJack Level 1

                    Thanks, Dave, for the assist; it works superbly!

                     

                    Many, many thanks, Jongware. I am inspired to compile scripts for a few other versions of photo captions via modifications of this script. Can you point me to where I can locate all of the Java properties available?

                     

                     

                    Jack

                    • 7. Re: ID CS3: How to place a rotated text box against the side of a photo box?
                      [Jongware] Most Valuable Participant

                      Hey, that must have changed from CS to CS3! (I wrote it for my home CS version). Thanks Dave ...

                       

                      For a full description of all objects, properties, and methods, check the ESTK Help menu. (Or try my personal version of the same data, http://www.jongware.com/idjshelp.html -- it contains a few more interconnected links than the ESTK version.)