• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Create TabStop via Javascript

Advocate ,
Jan 30, 2020 Jan 30, 2020

Copy link to clipboard

Copied

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

Views

1.3K

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 , 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,
...

Votes

Translate

Translate
Adobe
Advocate ,
Jan 30, 2020 Jan 30, 2020

Copy link to clipboard

Copied

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'. 

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

Copy link to clipboard

Copied

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

šŸ˜‰

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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

Copy link to clipboard

Copied

LATEST

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

 

Screen Shot 2020-01-31 at 2.20.26 PM.png

 

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

 

Thanks again.

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