Copy link to clipboard
Copied
Hi there
I am trying to make an Illustrator script that will change all numeric values in a drawing, but things are not going well.
I have some technical drawings with mesurements in mm, and I need to convert all to inches. The mesurements is just plain numbers - they are not to scale. The values are on their own layer.
I think it must be possible to make a script that takes all numeric values in a drawing, divide them by 25 (or something), and then put them back where they belong.
I hav seen a script for InDesign that does exactly that. It is called "Price adjuster" and it can adjust prices in for instance a cataloge, and convert prices from different currencys.
I have tried to make this script work in Illustrator, but unsurprisingly it did not work.
Can you suggest something?
var frames = app.activeDocument.textFrames;
for (var i = 0; i < frames.length; i++) {
if (isNaN(frames[i].contents)) {continue};
frames[i].contents = Number(frames[i].contents) / 25;
}
Copy link to clipboard
Copied
Please show something.
Are these real texts in Text frames?
Point text or area text?
There are text frames with other contents exists?
How the measurement is written/formatted?
[number][number][m][m] - 12mm
[number][number][space][m][m] - 12 mm
[number][number][dot][number][number][space][m][m] - 12.34 mm
[number][number][comma][number][number][space][m][m] - 12,34 mm
or in any other way?
Do you have an example document (with no confidential contents) for us for testing?
Copy link to clipboard
Copied
It's doable, but I suggest you show us your document, either by sharing a screenshot of the relevant content or, preferably, an AI file (for me this has to be CS6 compatible).
Copy link to clipboard
Copied
for a given text frame, you can do the following:
var myTextFrame = app.activeDocument.textFrames[0];
myTextFrame.contents = parseInt(myTextFrame.contents) * 25;
the "contents" property of the text frame is what holds the actual text that you can see. it's a string, so if you want to multiply it by something, you need to convert it to a number. Assuming you're working with integers, the above code should work fine. If you have decimals (floating points), then just swap parseInt() for parseFloat().
Then it's just a matter of running a loop of the above logic to change all the text frames.
Copy link to clipboard
Copied
Hi. Thank you for your answers.
I Tried your suggestion, DilliamWowling, and it works. But it would be nice if all the numbers could change in one go. I attach af sample file where the mesurements are in mm. These are the values that needs to be converted to inches.
Copy link to clipboard
Copied
var frames = app.activeDocument.textFrames;
for (var i = 0; i < frames.length; i++) {
if (isNaN(frames[i].contents)) {continue};
frames[i].contents = Number(frames[i].contents) / 25;
}
Copy link to clipboard
Copied
This is awesome! Thank you very much. All I have to do now is to ensure that all numbers are on the same layer. So I remove any text from the layer and Bingo!
Thanks