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

How to add or remove tab stops using ExtendScript

Advocate ,
Dec 07, 2023 Dec 07, 2023

I need to change the tabs in a paragraph via scripting. Here is what I have so far:

 

 

var oaTabs = oPgf.Tabs;
var oaNewTabs = [];
for( n = 0; n < oaTabs.length; n++ )
{
    if( oaTabs[n].x < iLeft || oaTabs[n].x > iRight ) 
        oaNewTabs.push( oaTabs[n] );
}
var oaProps = oPgf.GetProps( );
var i = GetPropIndex( oaProps, Constants.FP_Tabs );
oaProps[i].propVal.tsval = oaNewTabs;
oPgf.SetProps( oaProps );

 

 

 

Replacing the tsval inside the propVal for the paragaph tags does not work. I believe tsval is an alias to an array that is actually there, but what is the property name of the array that I need to replace ? Can this be done at all in this manner ?

 

Thanks for a quick reply

TOPICS
Scripting
421
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 , Dec 07, 2023 Dec 07, 2023

Hi Jang, instead of this:

 

var oaNewTabs = [];

 

try this:

 

var oaNewTabs = new Tabs ();

Let me know if that doesn't work and I will poke at it a little more. Thanks.

 

Translate
Community Expert ,
Dec 07, 2023 Dec 07, 2023

Hi Jang, instead of this:

 

var oaNewTabs = [];

 

try this:

 

var oaNewTabs = new Tabs ();

Let me know if that doesn't work and I will poke at it a little more. Thanks.

 

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 ,
Dec 07, 2023 Dec 07, 2023
LATEST

Hi Rick,

That works. Thanks. In the meantime I had also found another method. Not using the oPgf.Tabs property but going through GetProps method to assign the tsval to oaTabs. With that method, oaTabs seems to be the pointer to the right tsval structure in oaProps that I needed. Here is the working code:

var oaProps = oPgf.GetProps( );
var p = GetPropIndex( oaProps, Constants.FP_Tabs );
var oaTabs = oaProps[p].propVal.tsval;
var oaNewTabs = [];
for( n = 0; n < oaTabs.length; n++ )
    if( oaTabs[n].x < iLeft + 10 || oaTabs[n].x > iRight - 10 )
        oaNewTabs.push( oaTabs[n] );
while( oaTabs.length ) oaTabs.pop( );
for( n = 0; n < oaNewTabs.length; n++ ) oaTabs.push( oaNewTabs[n] );
oPgf.SetProps( oaProps );

The script is kicking out the tabs at positions between iLeft and iRight (which are calculated from the label text, which might be shorter or longer depending on content and language).

 

Kind regards

4everJang

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