Skip to main content
MarkWalsh
Inspiring
January 30, 2020
Answered

Create TabStop via Javascript

  • January 30, 2020
  • 3 replies
  • 1715 views

I need to create tabstops to text in a text frame in a javascript, but I don't see anything to allow me to do so.


The documentation only lists TabStopInfo properties, no 'add' method or any other methods for that object. (also, the example they list to display tab stop information has a bug in it). I tried using their example to see if the 'add' command would work but no such luck.

 

Is this feature not possible with Javascript? It's a problem for my current project if I cannot add tabs to a paragraph.

This topic has been closed for replies.
Correct answer pixxxelschubser

Hi @MarkWalsh

TabStops are an Array of TabStopInfo.

 

Here is an example for you:

// create a textFrame with a tabStop
// regards pixxxelschubser
var aDoc = app.activeDocument;
var aDocName = aDoc.name;
var mm = 2.834645;

var txtFrame = {position:[40,0], tab:[60]};
var t = new Array();
t[0] = new TabStopInfo;
t[0].position = txtFrame.tab[0]*mm;
t[0].alignment = TabStopAlignment.Decimal;
t[0].decimalCharacter = ",";

var aText = aDoc.textFrames.add();
aText.contents = aDocName + "   X: 40mm\t60,00 TabStop";
aText.left = txtFrame.position[0]*mm;
aText.top = txtFrame.position[1]*mm;
aText.paragraphs[0].tabStops = t;

 

Have fun

😉

3 replies

pixxxelschubser
Community Expert
Community Expert
January 31, 2020

You're welcome.

 

Quote: "… It would be helpful if the documentation had mentioned that it was an array …"

The OMV (Object Model Viewer) in ESTK shows exactly that:

MarkWalsh
MarkWalshAuthor
Inspiring
January 31, 2020

Yes, but I'm going by their Language Reference PDF:

 

 

Other places mention that something is an array of _______, but not this one.

 

Thanks again.

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
January 30, 2020

Hi @MarkWalsh

TabStops are an Array of TabStopInfo.

 

Here is an example for you:

// create a textFrame with a tabStop
// regards pixxxelschubser
var aDoc = app.activeDocument;
var aDocName = aDoc.name;
var mm = 2.834645;

var txtFrame = {position:[40,0], tab:[60]};
var t = new Array();
t[0] = new TabStopInfo;
t[0].position = txtFrame.tab[0]*mm;
t[0].alignment = TabStopAlignment.Decimal;
t[0].decimalCharacter = ",";

var aText = aDoc.textFrames.add();
aText.contents = aDocName + "   X: 40mm\t60,00 TabStop";
aText.left = txtFrame.position[0]*mm;
aText.top = txtFrame.position[1]*mm;
aText.paragraphs[0].tabStops = t;

 

Have fun

😉

MarkWalsh
MarkWalshAuthor
Inspiring
January 31, 2020

Excellent, thanks for the response and example.

 

It would be helpful if the documentation had mentioned that it was an array like they do everywhere else:

 

printerList array of Printer Read-only. The list of installed printers.

 

tabStops TabStopInfo Tab stop settings.

MarkWalsh
MarkWalshAuthor
Inspiring
January 30, 2020

This is the code I adapted from their example which didn't work:

 

docRef = app.activeDocument;
var tabRef;
var textRef = docRef.textFrames;
for( var i=0 ; i < textRef.length; i++ ) {
    // Get all paragraphs in the textFrames
    paraRef = textRef[i].paragraphs;
    for ( p=0 ; p < paraRef.length - 1  ; p++ ) {
        // Get para attributes for all textRanges in paragraph
        attrRef = paraRef[p].paragraphAttributes;

        tab = attrRef.tabStops.add()
        tab.alignment =  TabStopAlignment.Left
        tab.leader =  'X'
        tab.decimalCharacter =  'X'
        tab.position =  200
    } // end for
} // end for

I get "attrRef.tabStops.add is not a function'.