Copy link to clipboard
Copied
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;
}
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
...Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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
MM and every other Measurement setting.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks for your reply but it still does the same thing.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I suspected you were fibbing the whole time
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now