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.
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,
...
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'.
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
š
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.
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:
Copy link to clipboard
Copied
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.