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

Code to be evaluated! [004] // Round numbers! …

LEGEND ,
Nov 02, 2016 Nov 02, 2016

Copy link to clipboard

Copied

Hi all scripters,

Something is wrong: I can't find the way (surely obvious) to replace my numbers by their rounded values!! 

var myDoc = app.activeDocument; 

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = "\\d+\\.\\d+";

var myFound = myDoc.findGrep();

for (n = 0; n < myFound.length; n++){

        var myNum = myFound.contents;

        myNum = roundNumber (myNum);

};

app.findGrepPreferences = app.changeGrepPreferences = null;

function roundNumber (number) 

    { 

    number = Math.round(Number (number)); 

    return number; 

    }

Thanks in advance!

(^/)

TOPICS
Scripting

Views

316

Translate

Translate

Report

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

correct answers 1 Correct answer

Guru , Nov 02, 2016 Nov 02, 2016

Anytime dear 🙂

tpk1982​ I don't think Obi had a problem with that

Votes

Translate

Translate
LEGEND ,
Nov 02, 2016 Nov 02, 2016

Copy link to clipboard

Copied

Code given by Trevor, 3 years ago!

Re: It is possible to script a decimal approximation in Indesign?

Thanks Trevorׅ!

(^/)

var myDoc = app.activeDocument; 

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = "\\d+\\.\\d+";

var myFound = myDoc.findGrep();

n = myFound.length; 

while (n--) 

    { 

        app.changeGrepPreferences.changeTo = Math.round(myFound.contents).toString(); 

        myFound.changeGrep(); 

    }

app.findGrepPreferences = app.changeGrepPreferences = null;

Votes

Translate

Translate

Report

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
Guide ,
Nov 02, 2016 Nov 02, 2016

Copy link to clipboard

Copied

I think changeGrep() is missing in your code..

Votes

Translate

Translate

Report

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 ,
Nov 02, 2016 Nov 02, 2016

Copy link to clipboard

Copied

LATEST

Anytime dear 🙂

tpk1982​ I don't think Obi had a problem with that

Votes

Translate

Translate

Report

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