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

add page numbers via script

Explorer ,
Sep 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

I want to try to add page numbers to artboard based on position of selected text. I saw someone had made a script similar to this, but I need to do it based on selected text. Here is my solution, but for some reason it is not adding it based on artboard coordinates. I ran into this a while ago, and setting the rule to artboards fixed it, here it does not seem to have same effect.

#target illustrator

// global variables

////////////////////////////////////////////////////

// Set up varaibles

////////////////////////////////////////////////////

var pageNumber = app.activeDocument.artboards.getActiveArtboardIndex() + 1,

    doc = app.activeDocument;

//make sure only 1 item is selected

if(selectedItems.length > 1 || selectedItems.length < 1) {

    alert('please select only one item'}

else {

    var selectionTopPosition = doc.selection[0].top,

        selectionLeftPosition = doc.selection[0].left;

    doc.selection[0].remove();

    doc.selection = null;

    //remove selection

    //alert(selectionLeftPosition+" "+selectionTopPosition);

}

//create page numbers layer

var pageNumbersLayer = doc.layers.add();

pageNumbersLayer.name = "page numbers";

var pageNumbersLayerGroup = pageNumbersLayer.groupItems.add();

// main loop

//loop through artboards

for(i = 0; i < app.activeDocument.artboards.length; i++){

    app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

    doc.artboards.setActiveArtboardIndex(i);

    alert('active artboard is '+i);

    var pageNumber = doc.artboards.getActiveArtboardIndex() + 1;

    var pageCount = i + 1;

    var textRef = pageNumbersLayerGroup.textFrames.add();

    textRef.contents = pageCount.toString();

    textRef.top = selectionTopPosition;

    textRef.left = selectionLeftPosition;

    pageCount++;

}

TOPICS
Scripting

Views

1.9K

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

Community Expert , Sep 04, 2012 Sep 04, 2012

Have you tried to set the coordinate system for the specific doc.

Actually it worked for me with this

doc = app.activeDocument;

selectedItems = doc.selection;

I started with a single string (text) at the number location on artboard 1.

Screen shot 2012-09-04 at 1.58.56 PM.png

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 04, 2012 Sep 04, 2012

Copy link to clipboard

Copied

Have you tried to set the coordinate system for the specific doc.

Actually it worked for me with this

doc = app.activeDocument;

selectedItems = doc.selection;

I started with a single string (text) at the number location on artboard 1.

Screen shot 2012-09-04 at 1.58.56 PM.png

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
Explorer ,
Sep 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

oh wow, I'm a dummy! I somehow forgot to add that variable back in when I was piecing it together since I was testing it in pieces. thanks for the extra set of eyes! fixed it.

also I had to push the line:

app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;

into the first conditional, this is what was originally messing it up. I realized I got the position too late with wrong coordinate system. works perfect now.

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
New Here ,
Dec 03, 2016 Dec 03, 2016

Copy link to clipboard

Copied

LATEST

How can I get my script to note artboard coordinates and not document coordinates? This solves my problem, thank you.

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