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

Imperial/metric conversion of text

New Here ,
Sep 24, 2012 Sep 24, 2012

Hi everyone,

Im after a script or some direction for a script to convert a large number of text objects. I'd like to be able to convert from metres to yards and vice versa. All the text objects would be on the same layer and only contain integers and symbols such as (25) -23.

If the conversion could select all the text on one layer, and then convert and copy to a new layer it would be helpful but this can be done manually if needed. Is this possible? Im not familiar with scripting really but can learn what i need to get this script going. Any advice is appreciated.

Thanks

Alex

TOPICS
Scripting
2.6K
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
Adobe
Guru ,
Sep 25, 2012 Sep 25, 2012

This should give you a basic example… You can do this just using plain JavaScript Math or by using unitValues… This should be easy enough for you to play with… As is… it only works with text contents that are all numbers… You will need to explain further your text I think…

#target illustrator

addMeasurements();

function addMeasurements() {

   

    var i, doc, imp, met, txtItems, txt, nub;

    doc = app.activeDocument;

    imp = doc.layers.getByName( 'Inch' );

    met = doc.layers.add();  met.name = 'MM';

         

    txtItems = imp.textFrames;

    for ( i = 0; i < txtItems.length; i++ ) {

        txtItems.duplicate( met, ElementPlacement.PLACEATEND )

    };

    txtItems = met.textFrames;

    for ( i = 0; i < txtItems.length; i++ ) {

        var nub = parseInt( txt = txtItems.contents ); // For Numbers only!!!!

       

        txtItems.contents = String( nub * 2.83464567 )

    };

};

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
New Here ,
Sep 25, 2012 Sep 25, 2012

Thanks for the reply and script. Sorry i should have explained it a bit more, and also say that im working on a mac. Can i use or convert this in Applescript?

We have a multiple artboard project (about 50 artboards) with around 20-30 numbers on each artboard. These are meter measurements in the format that i showed initally, something like this 105 (101)

What we want to do is convert these measurements to yards, without having to do it manually, which take a long time. Im a cad user and have a great script i use to do things such as this in cad, but havent found the same thing for Illustrator.

Alex

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 ,
Sep 25, 2012 Sep 25, 2012

The above code is Abobe's ExtendScript this makes it good for both platforms… No need to convert… You can cut & paste from the forum into the ExtendScript Toolkit app that should be in your utilities folder? Just name/save it then put in AI presets folder…

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
New Here ,
Sep 25, 2012 Sep 25, 2012

Thats great. I'll give it a go.

Alex

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
New Here ,
Sep 25, 2012 Sep 25, 2012

The script is great thanks. Does pretty much what i need. Just wondering two things;

- Can it be made to round up ro down to whole numbers?

- Can it be made to read numbers that are between parentheses? In a text frame such as 100 (90)  it picks up the first number, however misses the second.

I found this script for Indesign, which i know is better at scripting than Illustrator, but looks fairly extensive.

http://indesignsecrets.com/free-script-to-change-all-numbers-in-a-document-using-math.php

I really appreciate what you have already done, very helpful thanks.

Alex

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 ,
Sep 25, 2012 Sep 25, 2012

The math thats in it at the moment is just inch to mm… Yep you can add a rounding function easy enough… What other characters are or can be in this text? and is 100 (90) in the same line of text?

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
New Here ,
Sep 25, 2012 Sep 25, 2012

I figured out the mulitplication factor and have it set at 1.1 for metres to yards, and will make a duplicate script for yards to metres aslo.

The lines will only ever be in about four formats, containing numbers, parentheses and - or + symbols;

000

000 (000)  or will be 2 digit numbers or combinatin of both

000  -0

000  +0    as 2 line text frame

(000)

No letters or other symbols are ever used.

Thanks

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
New Here ,
Oct 05, 2012 Oct 05, 2012
LATEST

Hi Mark,

Was wondering if you had anymore advice on this? Thanks

Alex

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