Auto Size text boxes

Learn / Forums / General InDesign Topics / Auto Size text boxes

Tagged: 

Viewing 10 reply threads
  • Author
    Posts
    • #100850

      I’m trying to set up a shortcut to change a text box to apply an auto size option in Text Frame Options/Auto Size. But I can’t seem to find one in the list that will take me there and change it to the height option I want. I see “Text Frame Options” in the list and I have a shortcut set up for that, but I want one that will take me farther into the options and change it to the height option I’m seeking. I also know I can set up an object style, but I’d have to do it for every existing job I open. Just trying to make it a single keystroke to change my height option.

    • #100894

      Hi Brenda, I don’t think that you can set a keyboard shortcut for that, I suggest to evaluate a search and replace with objects to apply what you need to. You can execute the search and replace to all the open documents.

      Hope this helps

    • #100916
      Vinny –
      Member

      Hi Brenda.
      I suppose this could be scripted. Then just apply a keyboard shortcut to the script.
      Here’s an example I just wrote (based on Adobe’s CreateCharacterStyle.jsx):
      Although I am very unsure how this WP forum handles codes and a bit worried it would remove some characters…

      main();
      function main(){
      //Make certain that user interaction (display of dialogs, etc.) is turned on.
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
      if (app.documents.length != 0){
      if (app.selection.length == 1){
      switch (app.selection[0].constructor.name){
      case “TextFrame”:
      myDefineObjectStyle();
      break;
      default:
      alert(“The selected object is not a text frame. Select some text and try again.”);
      break;
      }
      }
      else{
      alert(“Please select a single text frame and try again.”);
      }
      }
      else{
      alert(“No documents are open. Please open a document, select some text, and try again.”);
      }
      }

      function myDefineObjectStyle(myCharacterStyleName){
      var myDocument = app.activeDocument;
      var myObjectStyleName = “Auto-resize text frame height”;

      //Create the object style if it does not already exist.
      myObjectStyle = myDocument.objectStyles.item(myObjectStyleName);
      try{
      myObjectStyle.name;
      }
      catch (myError){
      myObjectStyle = myDocument.objectStyles.add({name:myObjectStyleName});
      }

      //Object Syle settings
      myObjectStyle.basedOn = myDocument.objectStyles[0];
      myObjectStyle.enableTextFrameAutoSizingOptions = true;
      myObjectStyle.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY; //Change if necessary
      myObjectStyle.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT; //Change if necessary

      myObjectStyle.enableFill = false;
      myObjectStyle.enableStroke = false;
      myObjectStyle.enableStrokeAndCornerOptions = false;
      myObjectStyle.enableParagraphStyle = false;
      myObjectStyle.enableTextFrameGeneralOptions = false;
      myObjectStyle.enableTextFrameBaselineOptions = false;
      myObjectStyle.enableStoryOptions = false;
      myObjectStyle.enableTextWrapAndOthers = false;
      myObjectStyle.enableAnchoredObjectOptions = false;
      myObjectStyle.enableFrameFittingOptions = false;

      }
      // Apply ObjectStyle to the selection
      var myObject = app.selection[0];
      myObject.appliedObjectStyle = myObjectStyle;

    • #100917
      Vinny –
      Member

      Hmmm not too bad… Apparently only quote marks have been converted.
      In your code editor, just change them back (both opening and ending) to straight quotes and it should be OK.
      ^^

    • #100918
      Vinny –
      Member

      Oh and the last 3 lines should come before the preceding brace }
      Pity we can’t edit posts…

    • #100919

      Do you have this as a link I can download? If I copy the script text, what would I put it into?

    • #100920
      Vinny –
      Member
    • #100926

      Vinny, that worked like a dream! Thanks so much! Would it be too much to ask to have a second one that would take it backwards? i.e., a script that would turn the AutoSize off.

    • #100929
      Vinny –
      Member

      Sorry Brenda, it’s weekend time…
      Besides, what’s the point? Are you just trying to fit frame to content with a shortcut? If that so, you should be able to achieve it without scripting.
      Could you be more specific about what exactly you want to do?
      Also please note the provided script not only turn on autosizing, but also applied an object style.

    • #100930

      I realized it created an object style after I manually changed a text box back to not having AutoSize. Because when I applied the script to a second text box on the same page, it made the first box go back to AutoSize and it lost my manual un-autosize. The reason I wanted a script to change it back to normal was because I like to use the AutoSize most of the time, but sometimes if I want to vertically center type in a box that is a certain depth, I have to go in and uncheck AutoSize. I don’t like to use “fit frame to content” for text because if I have to change the copy, it won’t automatically increase depth. But I appreciate your help with the script you created. I will continue to use it. Thanks so much!

    • #100951
      Vinny –
      Member

      Hi Brenda.
      So if I understand well, you want to some of switch.
      A script that would turn ON autosizing if it’s OFF and that would turn it OFF it was ON. Am I correct?
      If that so, you can try the script below: (don’t forget to change quote marks to straight ones)
      main();

      function main() {
      //Make certain that user interaction (display of dialogs, etc.) is turned on.
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
      if (app.documents.length != 0) {
      if (app.selection.length == 1) {
      switch (app.selection[0].constructor.name) {
      case “TextFrame”:
      AutosizeOnOff();
      break;
      default:
      alert(“The selected object is not a text frame. Select some text and try again.”);
      break;
      }
      } else {
      alert(“Please select a single text frame and try again.”);
      }
      } else {
      alert(“No documents are open. Please open a document, select some text, and try again.”);
      }
      }

      function AutosizeOnOff() {
      var myDocument = app.activeDocument;
      var myObject = app.selection[0];

      if (myObject.textFramePreferences.autoSizingType == AutoSizingTypeEnum.OFF) {
      myObject.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT; //Change if necessary. See https://jongware.mit.edu/idcs6js/pe_AutoSizingReferenceEnum.html
      myObject.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY; //Change if necessary. See https://jongware.mit.edu/idcs6js/pe_AutoSizingTypeEnum.html
      alert(“Autosizing is now ON”); // delete this line if you don’t want the alert box anymore
      } else {
      myObject.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF;
      alert(“Autosizing is now OFF”); // delete this line if you don’t want the alert box anymore
      }
      }

      Download link below:
      https://wetransfer.com/downloads/74d0c2189052ea61ce08f345896008d420180115083705/1192836602fa365851f4880b5dc73a3020180115083705/21a89c

      Let me know if it works for you
      Vinny

Viewing 10 reply threads
  • You must be logged in to reply to this topic.
>