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

Any help on getting sequential numbers to follow a path?

New Here ,
May 25, 2011 May 25, 2011

I have been trying to figure out how to get sequential number to follow a path. I am a complete rank amateur so think I have bitten off more that I can chew. I have been basing things on a JET_Numbered Callout script that I came accross and thought I would give it a go. It is an excellent script for generating sequential numbers even with a prefix, but am getting lost. I will keep going on it just thought I would post it incase the professional out there can take one look and say.. your barking up the wrong tree, have a rethink. Any guidence would be greatly appreciated.

the idea was to have 2 items, one text box and the other a path adn get the text box to fill with sequential numbers and follow the path at the pathPoints.

I think Im looking at this all too simplistically, but thought I would give it a go.

//--Begin Script--

//path to copy around

var docRef = app.activeDocument;

var objRef = docRef.selection[0];

var pathObject = docRef.selection[1];

var pointTotal = pathObject.pathPoints.length;

var startNode = pathObject.pathPoint;

var numPrefix=prompt("Type the desire name prefix of the selected object.","Item_");


var startNum=prompt("What number do you want to start with?",1);
var endNum=startNum + pointTotal - 1;
objRef.name=numPrefix+startNum;
objRef.contents=numPrefix+startNum;
startNum++;

for(i=startNum;i<=endNum;i++){
       
       var moveMult=0;
        var newObj=objRef.duplicate();
        newObj.name= numPrefix+i;
        newObj.contents=newObj.name;

        newObj.position=startNode[0+moveMult];
        moveMult++;

}

//--End Script---
TOPICS
Scripting
2.3K
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

Guide , May 26, 2011 May 26, 2011

#target illustrator function numberPathPoints() {      if (app.documents.length = 0) { return; }      var docRef = app.activeDocument;                 var sel = docRef.selection;                           if (sel.length == 1 && sel[0].typename == 'PathItem') {                                for (var i = 0; i < sel[0].pathPoints.length; i++) {                                var ppI = docRef.textFrames.add();                                ppI.contents = i;                                ppI.po

...
Translate
Adobe
Contributor ,
May 25, 2011 May 25, 2011

var docRef = app.activeDocument;

var objRef = docRef.selection[0];

var pathObject = docRef.selection[1];

var pointTotal = pathObject.pathPoints.length;

var startNode = pathObject.pathPoint;// this does not exist, either "pathPoints"is array or "pathPoints[number]"is a single point

var numPrefix=prompt("Type the desire name prefix of the selected object.","Item_");

var startNum=prompt("What number do you want to start with?",1);// startNum is a string not a number
var endNum=startNum + pointTotal - 1;
objRef.name=numPrefix+startNum;
objRef.contents=numPrefix+startNum;
startNum++;


for(i=startNum;i<=endNum;i++){
      
       var moveMult=0;//...because you set it here again


        var newObj=objRef.duplicate();
        newObj.name= numPrefix+i;
        newObj.contents=newObj.name;


        newObj.position=startNode[0+moveMult];//  pathPoint.anchor is a array of two numbers, should work
        moveMult++;// this cant work...


}

// i would do it like this
var text = app.selection[0];

var path =  app.selection[1];

var startNum=prompt("What number do you want to start with?",1)   *  1; //this will force a type conversion

var points = path.pathPoints;

for(i=0; i<points.length ;i++){

    var newtext=text.duplicate();
   
    newtext.contents =  "Item " +(i + startNum);
   
    newtext.position = points.anchor;

}

//chris

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
New Here ,
May 25, 2011 May 25, 2011

Thanks Chris... I see I was kinda on the right track but with glaring erros in my script.

I put this into place - the start numer prompt comes up and then errors after, see below

// start

var text = app.activeDocument.selection[0];  //added activeDocument as I am 'doing it by the book' and was hoping it would solve error.

var path = app.activeDocument.selection[1];

var startNum=prompt("What number do you want to start with?",1)   *  1; //this will force a type conversion

var points = path.pathPoints;

for(i=0; i< points.length ;i++){  //getting error here - undefined is not an object.

    var newtext=text.duplicate();
   
   
    newtext.name =  "Item " (i + startNum); //added to rename object item
   
    newtext.contents = "Real " (i + startNum); // changed string to differentiate when testing...havnt got this far yet.
   
    newtext.position = points.anchor;

}

//end
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
Contributor ,
May 25, 2011 May 25, 2011

has nothing to do with the error:

I forgot to declare iterator i as a local variable: var i=0 instead of i=0.

without var, i is global, you will get into hot hot water, dont do that.

ok, something is not defined, i is.  I think, points have no length, so the question is why.

you have to find out that.

maybe a alert(points.typename) before the error could help?

chris
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
New Here ,
May 25, 2011 May 25, 2011

Well I see

adde the var=i in but still something undefined, ran it throught eh script extendeder and it comes back with

var text = app.activeDocument.selection[0]; being undefined???????????

seems strange.  I have an active document, things are selected.

I am running this on CS2 but have been consulting the reference guide for CS3 as well.

something is strange. as it still goes through and asks me for the startNum etc.

Will keep hunting, thankyou for your help so far

Aaron

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
Guide ,
May 26, 2011 May 26, 2011

#target illustrator function numberPathPoints() {      if (app.documents.length = 0) { return; }      var docRef = app.activeDocument;                 var sel = docRef.selection;                           if (sel.length == 1 && sel[0].typename == 'PathItem') {                                for (var i = 0; i < sel[0].pathPoints.length; i++) {                                var ppI = docRef.textFrames.add();                                ppI.contents = i;                                ppI.position = sel[0].pathPoints.anchor;                      }      } }; numberPathPoints();

Just expects a single selected path item… Can also be helpful when scripting paths to see which way they run…

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
New Here ,
May 26, 2011 May 26, 2011

thanks very much mark, I have added the i+1 to the ppI.contents line below. I am going to keep playing on it to see what variables I can introduce but this definately gives me the engine. completely different way of thinking about it than the track I was heading down. WOW. but it all makes sense, which I think means I am learning something!

function numberPathPoints() {

     if (app.documents.length = 0) { return; }

     var docRef = app.activeDocument;
         
     var sel = docRef.selection;
                   
     if (sel.length == 1 && sel[0].typename == 'PathItem') {
                   
          for (var i = 0; i < sel[0].pathPoints.length; i++) {
              
               var ppI = docRef.textFrames.add();
              
               ppI.contents = i+1;
              
               ppI.position = sel[0].pathPoints.anchor;
         
          }

     }

};

numberPathPoints();

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
New Here ,
May 26, 2011 May 26, 2011
LATEST

big thanks to Chris and mark,  here is a mess around I just tried with the numbering script and a dup script as well.BIG THANKS!

I will post some more script like adding the start number and prefix etc when I have a play.

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