9 Replies Latest reply on Jun 15, 2016 2:02 PM by cbishop01

    Changing the Measurement Type?

    cbishop01 Level 2

      99% of my files are in inches but on the select few that is not they are in mm how can i get my below script to auto correct from inches to mm?  Right now everything moves perfectly where its supposed to go when the file is in inches.  But when i save in a Files built in mm it just puts a small line and i have to manually expand it. I figured when i made these sizes in inches it would adjust for it when using a mm FIle.

       function addTextFrame(doc, layer, name) {  
              var myBlendingSettings = { blendMode : BlendMode.OVERLAY };        
              var myTransparencySettings = { blendingSettings : myBlendingSettings };     
                
              var tf = doc.textFrames.itemByName(name);  
              if(tf && tf.isValid) {        
                  tf.remove();  
              }  
              tf = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {name: name, fillColor :"Yellow", fillTint: 20, transparencySettings : myTransparencySettings, geometricBounds: ['0in','-5.45in','1.45in','-.75in'] });        
                    return tf;  
          }  
      
        • 1. Re: Changing the Measurement Type?
          Trevorׅ Adobe Community Professional

          Hi

           

          If you have set the dimensions as a string i.e.

          app.activeDocument.textFrames.add({geometricBounds: ['0in','-5.45in','1.45in','-.75in'] });

          It shouldn't make any differences what the documents MeasurementUnits are.

          Sounds very much that either I am not understanding what you mean, maybe there's some missing details.

          What happens when you execute the above line on a document whose units are mm? (Pay attention to the - horizontal values)

          1 person found this helpful
          • 2. Re: Changing the Measurement Type?
            cbishop01 Level 2

            I probably didnt explain it well.  I'll post pics.  And it turns out that its not just mm its all sizes except for the Inches sizes that mess up The small bar is what shows up on everything except for the inches. 

            Inches

            Screen Shot 2016-06-10 at 7.27.59 AM.png

            MM and every other Measurement setting.

            Screen Shot 2016-06-10 at 7.29.06 AM.png

            • 3. Re: Changing the Measurement Type?
              Skemicle Level 3

                      function addTextFrame(doc, layer, name) {  

                      var myBlendingSettings = { blendMode : BlendMode.OVERLAY };        

                      var myTransparencySettings = { blendingSettings : myBlendingSettings };   

                      var tf = doc.textFrames.itemByName(name);

                      hm = app.activeDocument.viewPreferences.horizontalMeasurementUnits;

                      vm = app.activeDocument.viewPreferences.verticalMeasurementUnits;

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

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

                  if(tf && tf.isValid) {        

                          tf.remove();  

                      }  

                      tf = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {name: name, fillColor :"Yellow", fillTint: 20, transparencySettings : myTransparencySettings, geometricBounds: ['0in','-5.45in','1.45in','-.75in'] });        

                            return tf;  

                      app.activeDocument.viewPreferences.horizontalMeasurementUnits = hm;

                      app.activeDocument.viewPreferences.verticalMeasurementUnits = vm;

                   }

              Try this and let me know. Its The same code except i added lines 5-8 and15-16 to change your document settings to inches before adding the text frame and reset it back to the original setting afterwards

              • 4. Re: Changing the Measurement Type?
                cbishop01 Level 2

                Thanks for your reply but it still does the same thing.

                • 5. Re: Changing the Measurement Type?
                  vinothr Level 3

                  Hi,

                   

                  You are setting the geometric bounds values as string with "in" (inch) as prefix. There shouldn't be any problem irrespective of what the doc measurement unit. It should work as is. May be there is something else missing.

                   

                  Anyhow, if you cannot still find it, there is a way to set script preference measurement unit. You can even try the following.

                  But please note it is better you find the root cause.

                   

                          var origUnit = app.scriptPreferences.measurementUnit;       

                          app.scriptPreferences.measurementUnit = MeasurementUnits.INCHES;

                          tf = doc.textFrames.add(layer, LocationOptions.UNKNOWN, {name: name, fillColor :"Yellow", fillTint: 20, transparencySettings : myTransparencySettings,

                              geometricBounds: ['0','-5.45','1.45','-.75'] });         

                          app.scriptPreferences.measurementUnit = origUnit;

                   

                   

                  Make the bold changes in your function. And please note the "in" suffices removed in geometric bounds.

                  1 person found this helpful
                  • 6. Re: Changing the Measurement Type?
                    cbishop01 Level 2

                    I tried the origional script i had built and it worked no matter what units the Document was made in so i'm not sure where it went wrong here.

                    • 7. Re: Changing the Measurement Type?
                      cbishop01 Level 2

                      Ok i figured out what was causing this Problem.  I had a part of the script that Adjusted columns to be different sizes.  I had the size set on it but forgot to add the.  WHere the myWidths [] is i had it set to var myWidths=[1.35, 3.32]; I did not have the "in" after the size.  Adding the inches *in*after the Size fixed the problem below is the Code that fixed my problem.

                       

                       var myTable = addTable(tf);  
                                  setColumnWidthsAndAlignments(myTable)  
                          function setColumnWidthsAndAlignments(tableObj)  
                             {  
                              var myWidths=['1.32in', '3.37in', '0in', '0in'];  
                              var myAlignments=[Justification.LEFT_ALIGN,Justification.LEFT_ALIGN];  
                              var numberOfColumns=tableObj.columns.count();  
                              for (c=0;c<numberOfColumns;c++)  
                             {  
                                  myTable.columns[c].width=myWidths[c];  
                                  myTable.columns[c].cells.everyItem().texts.everyItem().justification=myAlignments[c];  
                             }  
                            }       
                      

                       

                      Thanks for your help guys

                      • 8. Re: Changing the Measurement Type?
                        Trevorׅ Adobe Community Professional

                        I suspected you were fibbing the whole time

                        • 9. Re: Changing the Measurement Type?
                          cbishop01 Level 2

                          Lol sorry i forgot i added the Table dimensions.    Thanks again for your all your help on this and all the other stuff i'm doing.