Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Changing the Measurement Type?

Advisor ,
Jun 09, 2016 Jun 09, 2016

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; 

    } 

TOPICS
Scripting
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Jun 10, 2016 Jun 10, 2016

        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.INC

...
Translate
Guru ,
Jun 09, 2016 Jun 09, 2016

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 10, 2016 Jun 10, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 10, 2016 Jun 10, 2016

        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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 10, 2016 Jun 10, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 10, 2016 Jun 10, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 15, 2016 Jun 15, 2016

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.width=myWidths

            myTable.columns.cells.everyItem().texts.everyItem().justification=myAlignments

       } 

      }      

Thanks for your help guys

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jun 15, 2016 Jun 15, 2016

I suspected you were fibbing the whole time

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 15, 2016 Jun 15, 2016
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 13, 2016 Jun 13, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines