Skip to main content
Participating Frequently
September 25, 2012
Question

Imperial/metric conversion of text

  • September 25, 2012
  • 1 reply
  • 2622 views

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

This topic has been closed for replies.

1 reply

Inspiring
September 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 )

    };

};

ozbongoAuthor
Participating Frequently
September 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

Inspiring
September 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…