4 Replies Latest reply on Jul 11, 2018 2:20 PM by neal derekl34934377

    CHANGE: font, font size, leading, kerning, tracking, etc of selected text frames

    neal derekl34934377 Level 1

      Was attempting to modify the below snippet to also affect selected text frames (as opposed to only the selected text within one text frame), in order to affect the text within those frames to assign text attributes to them.

       

      I attempted attaching .pageItem and .child etc but received  ‘object’ oriented errors.

       

      Ideally I want to attribute everything listed in the character panel to the selected text frames, in the below screenshot, (i.e. font family, font style name, font size, leading, kerning, tracking, etc.).

       

       

      Any help is very much appreciated.

       

      Cheers.

       

       

       

       

      var sel = app.selection;  
          for(var n=0;n<sel.length;n++)  
          {  
              sel[n].tracking=30; 
      sel[n].kerningMethod="Metrics"; 
          };  
      

       

       

      Screen Shot 2018-06-21 at 10.53.14 AM.png

        • 1. Re: CHANGE: font, font size, leading, kerning, tracking, etc of selected text frames
          Robert Kyle Level 2

          The textFrame object doesn't have properties like tracking, kerning etc. You need to address a text object.

           

          With one or more text frames, sel[n].texts[0] will return an object for the text of one of the selected frames. texts is an array but afaik it's always a one-item array. You can now manipulate the tracking etc. of the text.

           

          However, I suggest that you use sel[n].parentStory if at all possible. The difference is that parentStory addresses all of the text in the frame plus any that might be overset. texts[0] only gets the text that fits within the frame. Because you're working with tracking and kerning, there's a good chance that your script will change how the text flows so you might get unexpected results with texts[0]

           

          More advice that you did not ask for: Your posted snippet assumes that the script user will have selected one or more text frames. With a small number of careful users, that should work just fine. But if you're dealing with a larger number of users, you might want to include some logic in your script to handle the situations where someone has selected the text inside a frame or a group or a collection of page objects that might contain graphics frames, rules, etc. I have some snippets that might help.

           

          Bob

          3 people found this helpful
          • 2. Re: CHANGE: font, font size, leading, kerning, tracking, etc of selected text frames
            neal derekl34934377 Level 1

            Will implement these leads.

             

            Thank you.

             

            Stay tuned.

             

             

            I can say this will initially pertain to singular and/or groups of non-linked frames.

             

            But being aware of broader applications may come in handy for future use.

            • 3. Re: CHANGE: font, font size, leading, kerning, tracking, etc of selected text frames
              Robert Kyle Level 2

              Some snippets that might help:

               

              if (app.selection[0].hasOwnProperty("baselineShift"))

               

              is a quick way to determine if the user has clicked inside a text frame with the content tool. The actual selection could be a insertion point, character, word, line, etc., but they all have a baseline shift property. So if you want to operated on all of the text in that frame (plus anything that might overflow), get the parentStory. (Confession: I have stolen this snippet from someone else on this forum, but I forget who)

               

              If the result is false, the user might have selected a single page object or a collection of page objects. You might want to loop through them, testing the constructor.name to find the textFrames. If you encounter a group, get allPageItems of the group and loop through that array to find the textFrames. Once you have the textFrames, it's a short jump to the parentStory.

               

              Creative users can use the selection tools in surprising ways before running a script...

               

              Bob

              • 4. Re: CHANGE: font, font size, leading, kerning, tracking, etc of selected text frames
                neal derekl34934377 Level 1

                .parentStory saved the day.

                 

                From there on I was able to accomplish exactly what I needed, essentially getting rid of a object style (that affected the text frame and the text properties) and replacing said object style with a script instead.

                 

                Final script below fyi.

                 

                Thanks again, it’s really appreciated.

                 

                 

                 

                 var sel = app.selection; 
                    for(var n=0;n<sel.length;n++) 
                    { 
                        sel[n].parentStory.properties = {
                       
                tracking:0,
                kerningMethod:"Metrics",
                pointSize:6, 
                leading:6,
                baselineShift:0,
                appliedFont:"Gotham Narrow",
                fontStyle:"Medium",
                fillColor:"Black",
                fillTint:100,
                horizontalScale:100,
                verticalScale:100,
                skew:0,
                spaceAfter:0,
                spaceBefore:0,
                justification:Justification.CENTER_ALIGN,
                skew:0,
                allowArbitraryHyphenation:true,
                
                hyphenateAcrossColumns:true,
                hyphenateAfterFirst:1,   
                hyphenateBeforeLast:1,
                hyphenateCapitalizedWords:true,
                hyphenateLadderLimit:0,
                hyphenateLastWord:true,
                hyphenateWordsLongerThan:3,
                hyphenation:true,
                hyphenationZone:"0.1 in",
                
                };
                
                
                sel[n].textFramePreferences.properties = {
                
                  autoSizingReferencePoint: AutoSizingReferenceEnum.TOP_CENTER_POINT, 
                  autoSizingType: AutoSizingTypeEnum.HEIGHT_ONLY,
                insetSpacing: "0pt", 
                  ignoreWrap:true,
                  useMinimumWidthForAutoSizing:true,
                  minimumWidthForAutoSizing:"0 in",
                  useFixedColumnWidth:true,
                  textColumnFixedWidth:".3367 in",
                  verticalJustification:VerticalJustification.TOP_ALIGN,
                
                };
                
                    };