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

Simple calculation on selected number (Javascript)

Community Beginner ,
Sep 03, 2018 Sep 03, 2018

Copy link to clipboard

Copied

I would like to perform a simple calculation on a selected number using Javascript in InDesign CC.

To be clear, the script should get the selected number in a variable, perform a small calculation on it, and finally replace the selected text by the result.

Can someone help me on my way? Thanks!

TOPICS
Scripting

Views

731

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

People's Champ , Sep 03, 2018 Sep 03, 2018

Good point!

Votes

Translate

Translate
People's Champ ,
Sep 03, 2018 Sep 03, 2018

Copy link to clipboard

Copied

Well, presuming the user has selected some text, and to make sure it's a number:

myNumber = Number(app.selection[0].contents);

// Do a calculation

myNumber = myNumber + 5;

// Replace the selection

app.selection[0].contents = myNumber;

That's the basic skeleton of your script, I suppose...

HTH,

Ariel

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
Community Expert ,
Sep 03, 2018 Sep 03, 2018

Copy link to clipboard

Copied

app.selection[0].contents = String (myNumber);

P.

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
People's Champ ,
Sep 03, 2018 Sep 03, 2018

Copy link to clipboard

Copied

Good point!

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
Community Beginner ,
Sep 04, 2018 Sep 04, 2018

Copy link to clipboard

Copied

LATEST

Ariel,

Thanks a lot for your suggestion, it works and I am on my way.

Regards,

Peter

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