9 Replies Latest reply on Sep 1, 2016 10:49 AM by Loic.Aigon

    Change Text frame width from prompt

    tpk1982 Level 4

      Hi,

       

      I need to change the text frame width by getting values by prompt. Tried with resize method but not able to pass the prompt value.

       

       app.activeDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.INCHES;   
      app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.INCHES; 
      var myTableParent=app.activeDocument.selection[0].parentTextFrames[0]
      //~ var parentWidth = myTableParent.geometricBounds[3] - myTableParent.geometricBounds[1];
      var myvaluesprompt=prompt("Please enter the desired value (IN INCHES)","");
         
      myTableParent.resize(  
          CoordinateSpaces.pasteboardCoordinates,  
                CoordinateSpaces.INNER_COORDINATES,   
                AnchorPoint.TOP_LEFT_ANCHOR,   
                ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,  
                [myvaluesprompt, ResizeConstraints.KEEP_CURRENT_VALUE]  );
      

       

       

      Please select some text in the text frame. Hope you aware i used parenttextframe.

       

      Advance Thanks,

      K

        • 1. Re: Change Text frame width from prompt
          Loic.Aigon Adobe Community Professional
          var main = function() {
            var doc = app.properties.activeDocument,
            sel, nw;
            if(!doc || app.selection.length!=1) return;
          
          
            sel = app.selection[0];
            if ( sel.properties.parentStory || ! sel.properties.geometricBounds ) return;
          
            var p = prompt ("Please set a new width in inches", "");
          
            if ( !p || !/^\d+(\.\d+)?$/.test(p) ) {
            alert("Wrong value !");
            return;
            }
          
            nw = new UnitValue ( p, "in" ).as("pt");
          
            sel.resize ( 
            CoordinateSpaces.INNER_COORDINATES, 
            AnchorPoint.TOP_LEFT_ANCHOR,  
            ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,    
            [nw, ResizeConstraints.KEEP_CURRENT_VALUE] 
            ); 
          
          }
          
          
          main();
          

           

           

          HTH

           

          Loic

          Ozalto | Productivity Oriented - Loïc Aigon

          • 2. Re: Change Text frame width from prompt
            tpk1982 Level 4

            Thank you Loic, but if i run the script it wont did anything. It just returned.. not sure why it return without do any action

            • 3. Re: Change Text frame width from prompt
              tpk1982 Level 4

              It run if i comment the line 8

               

              Screen Shot 2016-09-01 at 6.37.57 PM.png

              • 4. Re: Change Text frame width from prompt
                Loic.Aigon Adobe Community Professional

                Hi,

                 

                The line

                if ( sel.properties.parentStory || ! sel.properties.geometricBounds ) return

                specifically intends to check if the selection is resizable(by having geometric bounds property)

                If you comment it, you will certainly face errors as the selection may not be resizable (think of some selected text).

                 

                The fact your first call does nothing means the selection is not valid (i.e. not a resizable pageItem).

                 

                FWIW

                 

                Loic

                • 5. Re: Change Text frame width from prompt
                  tpk1982 Level 4

                  Hi Loic,

                   

                  Initially i tested with selection of text and ran the script. It wont respond. So only i just comment that.

                   

                  Please select some text in the text frame. Hope you aware i used parenttextframe. (from my OP)

                   

                  Thanks,

                  Karthi

                  • 6. Re: Change Text frame width from prompt
                    Loic.Aigon Adobe Community Professional

                    Hi,

                     

                    so it's just a small adjustment:

                     

                    var main = function() {
                      var doc = app.properties.activeDocument,
                      sel, nw;
                      if(!doc || app.selection.length!=1) return;
                    
                    
                      sel = app.selection[0];
                    
                      if ( sel.properties.parentStory  && !sel.properties.geometricBounds ) {
                      if ( !sel.parentTextFrames.length ) {
                      alert("You selected text but parent text frame is not accessible at the moment. Text must be overflowing…" );
                      return;
                      }
                      sel  = sel.parentTextFrames[0];
                      }
                    
                      var p = prompt ("Please set a new width in inches", "");
                    
                      if ( !p || !/^\d+(\.\d+)?$/.test(p) ) {
                      alert("Wrong value !");
                      return;
                      }
                    
                      nw = new UnitValue ( p, "in" ).as("pt");
                    
                      sel.resize ( 
                      CoordinateSpaces.INNER_COORDINATES, 
                      AnchorPoint.TOP_LEFT_ANCHOR,  
                      ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,    
                      [nw, ResizeConstraints.KEEP_CURRENT_VALUE] 
                      ); 
                    
                    }
                    
                    
                    main();
                    
                    • 7. Re: Change Text frame width from prompt
                      Laubender Adobe Community Professional & MVP

                      Hi Loic,

                      I just tested your first snippet on a selected text frame ( containing a table that overflows* ).
                      * If that is important at all.

                       

                      OSX 10.6.8 with InDesign CS6 v8.1.0.

                       

                      It will do nothing.
                      If I strip all the code down to its bare functionality it will work as expected:

                       

                      var sel = app.selection[0];
                      var p = prompt("Please set a new width in inches", "");  
                      var nw = new UnitValue ( p, "in" ).as("pt");  
                      
                      sel.resize
                      (   
                        CoordinateSpaces.INNER_COORDINATES,   
                        AnchorPoint.TOP_LEFT_ANCHOR,    
                        ResizeMethods.REPLACING_CURRENT_DIMENSIONS_WITH,      
                        [nw, ResizeConstraints.KEEP_CURRENT_VALUE]   
                      );
                      

                       

                      Did not test further…

                       

                      Best,

                      Uwe

                      1 person found this helpful
                      • 8. Re: Change Text frame width from prompt
                        tpk1982 Level 4

                        Hi Loic,

                         

                        It is working perfectly

                         

                        @Uwe: Thanks Uwe, it also doing the job correctly.

                         

                        Regards,

                        K

                        • 9. Re: Change Text frame width from prompt
                          Loic.Aigon Adobe Community Professional

                          Hi Uwe,

                           

                          Laubender a écrit:

                           

                          Hi Loic,

                          I just tested your first snippet on a selected text frame ( containing a table that overflows* ).
                          * If that is important at all.

                           

                          OSX 10.6.8 with InDesign CS6 v8.1.0.

                           

                          It will do nothing

                          That's logical given that it only considered a valid selection would be a pageItem other that a text frame. I ignored that part of the context at first.