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

Create TabStop via Javascript

Advocate ,
Jan 30, 2020 Jan 30, 2020

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.

TOPICS
Scripting
1.6K
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

Community Expert , Jan 30, 2020 Jan 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,
...
Translate
Adobe
Advocate ,
Jan 30, 2020 Jan 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'. 

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
Community Expert ,
Jan 30, 2020 Jan 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

😉

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
Advocate ,
Jan 31, 2020 Jan 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.

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
Community Expert ,
Jan 31, 2020 Jan 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:

OMV_tabStop.pngexpand image

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
Advocate ,
Jan 31, 2020 Jan 31, 2020
LATEST

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

 

Screen Shot 2020-01-31 at 2.20.26 PM.pngexpand image

 

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

 

Thanks again.

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