Skip to main content
Participant
April 24, 2017
Answered

Converting MM to inches in text

  • April 24, 2017
  • 1 reply
  • 1811 views

Hey guys,

I was wondering if there is an automated way, to conver mm in a document to i nches by running a script. See the below, i have tables and text like this:

Installation Dimensions (WxDxH)

224 x 534 x 667  mm

236 x 569 x 428.5 mm

231 x 600 x 430 mm

231 x 438 x 600 mm

255 x 486 x 404 mm

351 x 454 x 513 mm

It would be amazing life i could automate it rather then manually having to go the document through to do it.

This topic has been closed for replies.
Correct answer Jongware

're you go. I didn't want to wait for that accuracy so I took the usual mils (3).

app.findGrepPreferences = null;

app.findGrepPreferences.findWhat = "\\d+(\\.\\d*)?\\s+x\\s+\\d+(\\.\\d*)?\\s+x\\s+\\d+(\\.\\d*)?\\s+mm\\b";

var list = app.activeDocument.findGrep( false);

while (list.length)

{

item = list.pop();

text = item.contents;

// mm to in at the end

text = text.replace('mm', 'inch')

// convert values

text = text.replace(/\d+(\.\d*)?/g, function(val) { return Math.round(1000*parseFloat(val)/25.4)/1000; })

item.contents = text;

}

This is typical No Guarantees Software; make sure to save a copy first!

1 reply

Jongware
Community Expert
Community Expert
April 24, 2017

Piece of cake. Lots of such scripts already exist but someone can write it faster from scratch than you can find one online.

How many decimals of accuracy do you need?

Obi-wan Kenobi
Legend
April 24, 2017

Just do a research on: Peter Kahrel or Steve Wareham!

(^/)