10 Replies Latest reply on Jul 7, 2016 4:46 AM by Maggern78

    Add a little height to text box in indesign?

    Maggern78

      Hi!

       

      I have a big and nice script that applies height/width changes to a document based on object styles and other parameters.

      But what I really need is a script that just adds a little height to a selected text box. It does not have to rely on object styles and should apply only to one box.

       

      I'm learning to program, but have no javascript skills so far...

      Is there any way to cut down the script under?

       

       

      (Source: https://forums.adobe.com/thread/628574)

       

      // setBoundsOfObjectsWithAppliedObjectStyle.jsx  

       

      //DESCRIPTION: change the metrics of objects applied with certain object style

      // 2010/02  

        

      var doc = app.documents.firstItem();  

      var the_operator = ['absolut', 'addieren', 'multiplizieren', 'prozentual skalieren']; 

      var r = get_param(doc.objectStyles.everyItem().getElements().slice(0),  the_operator);  

      var  f_objects = get_objects ( r.style);  

      apply_values(f_objects, r, the_operator);  

        

        

      function apply_values(the_objects, r)  

      {  

          for (var i = the_objects.length - 1; i >= 0; i--)  

          {  

              var gb = the_objects[i].visibleBounds;  

              if (r.op == the_operator[0]) //'absolut')  

              {  

                  var _y2 = (r.height != 0)  

                      ? gb[0] + r.height  

                      : gb[2];  

                  var _x2 = (r.width != 0)  

                      ? gb[1] + r.width  

                      : gb[3];  

              }  

              else if (r.op == the_operator[2] || r.op == the_operator[3]) //'multiplizieren' oder 'prozentual skalieren' 

              {  

                  var the_div = (r.op == the_operator[2]) //'multiplizieren') 

                      ? 1 

                      : 100; 

                  var _y2 = (r.height != 0)  

                      ? gb[0] + (gb[2]-gb[0]) * r.height/the_div  

                      : gb[2];  

                  var _x2 = (r.width != 0)  

                      ? gb[1] + (gb[3]-gb[1]) * r.width/the_div  

                      : gb[3];  

              }  

              else if (r.op == the_operator[1]) //'addieren' ) 

              { 

                  var _y2 = gb[2] + r.height;  

                  var _x2 = gb[3] + r.width; 

              } 

              the_objects[i].visibleBounds = [gb[0], gb[1],  _y2 , _x2];   

          }  

      }  

        

      function get_objects(a_style)  

      {  

          app.findObjectPreferences = null;  

          app.findChangeObjectOptions.objectType = ObjectTypes.ALL_FRAMES_TYPE;  

          app.findObjectPreferences.appliedObjectStyles =a_style;  

          var the_result = doc.findObject();  

          app.findObjectPreferences = null;  

          return the_result;  

      }  

        

      function get_param(_styles, the_operator)  

      {  

          var style_names = new Array;  

          //Ausklammern von '[Einfaches Raster]'  

          for (var a = 1; a < _styles.length; a++)  

              style_names.push(_styles[a].name);  

          var min_width = 140; 

          var field_width = 40; 

          var myDialog = app.dialogs.add({name:"Breite und Höhe von Objekten verändern"});   

          with( myDialog.dialogColumns.add())   

          {   

              with(dialogRows.add())   

              {  

                  with(dialogColumns.add())   

                  {   

                      staticTexts.add({staticLabel:"Objektstil:",    minWidth:min_width});   

                  }   

                  with(dialogColumns.add())   

                  {   

                      var myStylesDropDown = dropdowns.add({stringList:style_names,    selectedIndex:style_names.length-1, minWidth:min_width});   

                  }   

              }   

              with(dialogRows.add())   

              {   

                  with(dialogRows.add())   

                  {   

                      with(dialogColumns.add())   

                      {   

                          staticTexts.add({staticLabel:"Breite:",    minWidth:min_width});   

                      }   

                      with(dialogColumns.add())   

                      {   

                          var myWidthTextEditbox = textEditboxes.add({editContents:"0",    minWidth:field_width});   

                      }   

                  }   

                  with(dialogRows.add())   

                  {   

                      with(dialogColumns.add())   

                      {   

                          staticTexts.add({staticLabel:"Höhe:",    minWidth:min_width});   

                      }   

                      with(dialogColumns.add())   

                      {   

                          var myHeightTextEditbox = textEditboxes.add({editContents:"0",    minWidth:field_width});   

                      }   

                  }   

                  with ( dialogRows.add () ) {   

                      with(dialogColumns.add())  {                     

                      staticTexts.add( {staticLabel: "Operation: ", minWidth: min_width} ); 

                      } 

                      with(dialogColumns.add())   

                      { 

                          var radio_buttons = radiobuttonGroups.add(); 

                          with(radio_buttons) { 

                              radiobuttonControls.add({staticLabel: the_operator[0], checkedState: true, minWidth: min_width}); 

                              radiobuttonControls.add({staticLabel: the_operator[1], checkedState: false, minWidth: min_width}); 

                              radiobuttonControls.add({staticLabel: the_operator[2], checkedState: false, minWidth: min_width}); 

                              radiobuttonControls.add({staticLabel: the_operator[3], checkedState: false, minWidth: min_width}); 

                          } 

                      } 

                  } 

              }  

          }   

          var myResult = myDialog.show();   

          if(myResult == true)   

          {   

              var a_style = doc.objectStyles.item(myStylesDropDown.selectedIndex);   

              var a_width = Number(myWidthTextEditbox.editContents.replace(',','.'));  

              var a_height = Number(myHeightTextEditbox.editContents.replace(',','.'));  

              var a_operator = the_operator[radio_buttons.selectedButton]  

              if (isNaN (a_width))  

                  a_width = 0;  

              if (isNaN (a_height))  

                  a_height = 0;  

              myDialog.destroy();   

          }   

          else   

          {   

              myDialog.destroy();   

              exit();  

          }   

          return {style:a_style, width: a_width, height: a_height, op: a_operator};