Copy link to clipboard
Copied
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
Try to change this line,
var newNumber = parseFloat(startNum) + (a+1) ;
to
var newNumber = parseFloat(startNum) + (a+1) * increment;
Copy link to clipboard
Copied
Try to change this line,
var newNumber = parseFloat(startNum) + (a+1) ;
to
var newNumber = parseFloat(startNum) + (a+1) * increment;
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Any further updates for the above.
Copy link to clipboard
Copied
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)]
}
Copy link to clipboard
Copied
Thanks for update Ten,
I am not so good in scripting, could you please update this for me.
Regards,
Vinoth
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks a lot. surely i am in the learning process.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You can use toFix method like below.
var pai = 3.1415926535897932;
var fixedValue = pai.toFix(1);
Copy link to clipboard
Copied
Great i solved this issue, Thanks