Skip to main content
Known Participant
March 18, 2024
Answered

activate artboard and layer

  • March 18, 2024
  • 1 reply
  • 745 views

Kindly see the attached Word document for a description of my issue.  I will copy the word document here:

Hello all,

Once again, my frustration level has exceeded my usually high tolerance level, and I am seeking your help and guidance.

 

I am trying to develop a script that will produce a sequence of numbers either with or without a prefix or suffix to be used in a wide variety of applications.  A sequence of numbers to label lab specimens; a sequence of numbers representing electronic microscope images of a specific object; a sequence of numbers representing pages in a notebook.  I even want a sequence of numbers showing dates of coins that I collect. You get the idea.  For years I have typed these sequences by hand or had someone else type in the numbers.  What a great idea for a script.  If only I could write one that worked!

 

Outline of my ideas:

  1. Get data – starting number, ending number, prefix, suffix, number of leading zeros, etc.
  2. Calculate the number of pages needed to make the sequence.  I have used up to 8 pages in the past.
  3. Generate an artboard and layer for each page.  I know that no data is stored in the artboards, but I still need sheets of paper to fill and will hold data in the layer.
  4. Produce one page (artboard) at a time with part the list of numbers / sequences. Save the document. Then, move on to the next page.  Simple!

 

I believe the key to addressing multiple pages and layers is through activation.  I mention this as I might be way off base with this idea. I want to activate an artboard and associated layer.  Fill the page with part of the sequence, save the document, then switch to the next artboard and layer and continue with the sequence.

 

So far, I have utterly failed to get this to work.  A simple test application is shown.  Two artboards and two layers are generated.  The first artboard and second layer is activated and a text frame is made to hold a sentence.  Next an attempt to activate the second artboard and third layer is made and a new text frame with a sentence is written to the newly activated layer and sequence.

 

What happens is that both sentences appear on artboard 1 and in layer 2.  Screen shot made; not sure if allowed but will try.

 

Kindly have a look and let this idiot know what I am doing wrong.

 

Many many thanks for taking the time to look at this problem and taking the time to correct my thinking or code or idea.

 

Over and out, Kent

 

This topic has been closed for replies.
Correct answer dolce5EC2

Hello, EyeballDoc

few things - setActiveArtboardIndex is a function not an array, so correct syntax should be setActiveArtboardIndex(1);
whilst target.activeLayer = target.layers[0]; is acceptable, you can also add tf's directly: target.layers[0].textFrames.add(), or even better - layer_01.textFrames.add()

 

..and to answer your question...things work a bit different... you have mentioned that 'I know that no data is stored in the artboards,' and that was a very correct observation. 

 

instead of activating artboard and trying to put things into it it, you have to position objects on artboard coordinates.
for that there is a very helpful property - which is a 4 number array - 

 

artboard.artboardRect = [left,top, right,bottom] 

 

so your logic should be: 

get artboard you want to place things onto

get its rect

use rect coordinates to position things

 

var ab=target.artboards[1];

var abr=ab.artboardRect;

TF_2.position = [40+ abr[0] , -350+abr[1]];

dont forget inverted y coordinate system! 

good luck!

 

1 reply

dolce5EC2Correct answer
Inspiring
March 19, 2024

Hello, EyeballDoc

few things - setActiveArtboardIndex is a function not an array, so correct syntax should be setActiveArtboardIndex(1);
whilst target.activeLayer = target.layers[0]; is acceptable, you can also add tf's directly: target.layers[0].textFrames.add(), or even better - layer_01.textFrames.add()

 

..and to answer your question...things work a bit different... you have mentioned that 'I know that no data is stored in the artboards,' and that was a very correct observation. 

 

instead of activating artboard and trying to put things into it it, you have to position objects on artboard coordinates.
for that there is a very helpful property - which is a 4 number array - 

 

artboard.artboardRect = [left,top, right,bottom] 

 

so your logic should be: 

get artboard you want to place things onto

get its rect

use rect coordinates to position things

 

var ab=target.artboards[1];

var abr=ab.artboardRect;

TF_2.position = [40+ abr[0] , -350+abr[1]];

dont forget inverted y coordinate system! 

good luck!

 
Known Participant
March 19, 2024

Flawless and thank you.