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

Increment text value in illustrator

Explorer ,
Sep 06, 2017 Sep 06, 2017

Hi All,

i have found the below script for text increment in illustrator this is working fine, but i need the increment value to be variable

If the starting number is 7 and the increment value is 7 and number of steps is 5 then our requirement would be 7,14, 21,28,35.

#target illustrator

var selectedItems;

// if a document is open

if(documents.length >0)

{

    var idoc = app.activeDocument;  

   // if textframes exist in the document

   if(activeDocument.textFrames.length > 0)

   {

      // check to make sure something is selected.

      selectedItems = selection

      if (selectedItems.length > 0)

      {

            var itemFound = false;

            for(var i=0; i<selectedItems.length; i++)

            {

               if(selectedItems.typename == "TextFrame")

               {

                  itemFound = true;

                  alert ("The following text item is selected: >" + selectedItems.contents + "<")

                  var startNum = prompt ("Enter a starting number");

                  var incY = prompt ("Enter a Y offset in points (72 points = 1 inch)", "72", "Y Offset");

                  var steps = prompt ("How many steps?");

                  var increment = prompt ("count?"); //Added new

               

                  selectedItems.contents = startNum;

                  var myGroup = app.activeDocument.groupItems.add();

                  selectedItems.move( myGroup , ElementPlacement.PLACEATEND);

                  selectedItems.position = [0,0];

                  for(var a=0; a<steps; a++)

                  {               

                      selectedItems.duplicate ();

                      selectedItems.move( myGroup , ElementPlacement.PLACEATEND);

                      var newNumber = parseFloat(startNum) + (a+1);

                      selectedItems.contents = newNumber;

                      var newY = incY / 72;

                      selectedItems.position = [0, -((a+1)*incY)];

                   }

               }

            }

            if(itemFound == false) alert("No text items are selected.");

      }

      else

      {

         alert("Nothing is selected, select a text item(s) or a text range.");

      }

   }

   else

   {

      alert("Open a document and select 1 or more text items or a text range.");

   }

}

else

{

   alert("Open a document and select 1 or more text items or a text range.");

}

Regards,

Vinoth

TOPICS
Scripting
3.0K
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

correct answers 1 Correct answer

Community Expert , Sep 06, 2017 Sep 06, 2017

Try to change this line,

var newNumber = parseFloat(startNum) + (a+1) ;

to

var newNumber = parseFloat(startNum) + (a+1) * increment;

Translate
Adobe
Community Expert ,
Sep 06, 2017 Sep 06, 2017

Try to change this line,

var newNumber = parseFloat(startNum) + (a+1) ;

to

var newNumber = parseFloat(startNum) + (a+1) * increment;

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
Explorer ,
Sep 06, 2017 Sep 06, 2017

Thanks for the update, its working.

selectedItems.position = [0,0];

Instead of [0,0]; position the text has to be retained in the same position where the text is selected, it that is possible.

Regards,

Vinoth

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
Explorer ,
Sep 13, 2017 Sep 13, 2017

Any further updates for the above.

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
Community Expert ,
Sep 13, 2017 Sep 13, 2017

You can reference selected objects position, duplicate it and move it. reference below

var pos = selectedItems.position;

for(.....){

   SelectedItems.position = [pos[0], pos[1]-((a+1)*incY)]

}

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
Explorer ,
Sep 13, 2017 Sep 13, 2017

Thanks for update Ten,

I am not so good in scripting, could you please update this for me.

Regards,

Vinoth

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
Community Expert ,
Sep 15, 2017 Sep 15, 2017

Try it

#target illustrator

var selectedItems, pos;

// if a document is open

if(documents.length >0)

{

    var idoc = app.activeDocument; 

   // if textframes exist in the document

   if(activeDocument.textFrames.length > 0)

   {

      // check to make sure something is selected.

      selectedItems = selection

      if (selectedItems.length > 0)

      {

            var itemFound = false;

            for(var i=0; i<selectedItems.length; i++)

            {

               if(selectedItems.typename == "TextFrame")

               {

                  itemFound = true;

                  alert ("The following text item is selected: >" + selectedItems.contents + "<")

                  var startNum = prompt ("Enter a starting number");

                  var incY = prompt ("Enter a Y offset in points (72 points = 1 inch)", "72", "Y Offset");

                  var steps = prompt ("How many steps?");

                  var increment = prompt ("count?"); //Added new

              

                  selectedItems.contents = startNum;

                  var myGroup = app.activeDocument.groupItems.add();

                  selectedItems.move( myGroup , ElementPlacement.PLACEATEND);

                  //selectedItems.position = [0,0]; //ignore this line.

                  pos = selectedItems.position; //get original objects position(x,y cordinates) in Array.

                  for(var a=0; a<steps; a++)

                  {

                      selectedItems.duplicate ();

                      selectedItems.move( myGroup , ElementPlacement.PLACEATEND);

                      var newNumber = parseFloat(startNum) + (a+1);

                      selectedItems.contents = newNumber;

                      var newY = incY / 72;

                      selectedItems.position =  [pos[0], pos[1]-((a+1)*incY)]; //

                   }

               }

            }

            if(itemFound == false) alert("No text items are selected.");

      }

      else

      {

         alert("Nothing is selected, select a text item(s) or a text range.");

      }

   }

   else

   {

      alert("Open a document and select 1 or more text items or a text range.");

   }

}

else

{

   alert("Open a document and select 1 or more text items or a text range.");

}

However, I recommend you to learn around Scripting. Actually, We don't have enough time to write for someone and you don't always get it.

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
Explorer ,
Sep 18, 2017 Sep 18, 2017

Thanks a lot. surely i am in the learning process.

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
Explorer ,
Sep 19, 2017 Sep 19, 2017

In the decimal value for example 0.5 , 1.0 , 1.5 , 2.0. etc the value are found as 0.5 , 1 , 1.5 , 2. the value of 0 is missing after round value.

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
Community Expert ,
Sep 19, 2017 Sep 19, 2017

You can use toFix method like below.

var pai = 3.1415926535897932;

var fixedValue = pai.toFix(1);

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
Explorer ,
Sep 19, 2017 Sep 19, 2017
LATEST

Great i solved this issue, 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