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

Code to be evaluated! [016] Tabs Position! …

LEGEND ,
Mar 05, 2017 Mar 05, 2017

Copy link to clipboard

Copied

Hi All,

The deal is simple:

You select text with tabs and run the script below! You just need to enter the new font size!

Capture d’écran 2017-03-06 à 02.56.19.png

The script seems to work! The position of the tabs is recalculated, depending on the new font size, here 16 pts => 8 pts!

Capture d’écran 2017-03-06 à 02.59.52.png

… If I want to go back (no undo!): 8 pts => 16 pts and run the script again:

Capture d’écran 2017-03-06 à 03.00.13.png

No idea to correct this!  Thanks for help! 

var w = new Window ('dialog {alignChildren: "top"}', 'New Tabs position! …');

w.alignChildren = "right";

    var group1 = w.add ('group');

        group1.add ('statictext {text: "New Font Size:"}');

    var UIy = group1.add ("edittext", undefined, 0);

        UIy.characters = 5;

        UIy.minimumSize.width = 60;

        UIy.maximumSize.width = 60;

        UIy.active = true;

    var buttons = w.add ('group {alignment: "center"}');

        buttons.add ('button {text: "OK"}');

        buttons.add ('button {text: "Cancel"}');

    var group2 = w.add ('group');

        group2.add ('statictext {text: "(by Michel Allio, March 2017)"}');

if ( w.show () == 1 )  var y = Number (UIy.text);

else  exit();

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "New Tabs position! …");

function main()    

    {

        var mySel = app.selection[0],

        myStops = mySel.tabStops,

        S = myStops.length,

        x = mySel.pointSize;

        mySel.pointSize = y;

        for ( var s = 0 ; s < S; s++ )  myStops.position = myStops.position/x*y;

    }

(^/)

TOPICS
Scripting

Views

478

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

Enthusiast , Mar 06, 2017 Mar 06, 2017

Je viens de faire des tests là ça fonction mais probablement incomplet dans les propriété :

/...

var positions=[];

   for ( var s = 0 ; s < S; s++ )  {

      

            positions.push([myStops.alignment, myStops.position] );

    }

    myStops.everyItem().remove();

     for ( var s = 0 ; s < S; s++ )  {

           mySel.tabStops.add({alignment:positions[0], leader:"", position:(positions[1]/x*y)})

     }

.../

Votes

Translate

Translate
Mentor ,
Mar 06, 2017 Mar 06, 2017

Copy link to clipboard

Copied

Hi,

For me it looks like direction of loop matter.

If original pointSize is higher than UI value ==> step++

Else ==> step --

/...

        if (mySel.pointSize > y)

            for ( var s = 0 ; s < S; s++ )

                myStops.position = myStops.position/x*y;

      else

            for ( var s = S-1 ; s >= 0; s-- )

                myStops.position = myStops.position/x*y;

//...

Thats to avoid interaction inbetween currently modified tabStop and the next ones (which possibly would change a position [index])

Jarek

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
Enthusiast ,
Mar 06, 2017 Mar 06, 2017

Copy link to clipboard

Copied

Hi,

The problem seems to be when a position exceeds or comes before another tab order is no longer good, right?

Bonjour

Le problème semble être quand une position dépasse ou viens avant un autre tabulation l'ordre n'est plus bon, non?

Philippe

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
Enthusiast ,
Mar 06, 2017 Mar 06, 2017

Copy link to clipboard

Copied

Je viens de faire des tests là ça fonction mais probablement incomplet dans les propriété :

/...

var positions=[];

   for ( var s = 0 ; s < S; s++ )  {

      

            positions.push([myStops.alignment, myStops.position] );

    }

    myStops.everyItem().remove();

     for ( var s = 0 ; s < S; s++ )  {

           mySel.tabStops.add({alignment:positions[0], leader:"", position:(positions[1]/x*y)})

     }

.../

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
LEGEND ,
Mar 06, 2017 Mar 06, 2017

Copy link to clipboard

Copied

LATEST

Thanks Jarek and Philippe!

I think it works fine now as:

function main()    

    {

        var mySel = app.selection[0],

        myStops = mySel.tabStops,

        S = myStops.length,

        x = mySel.pointSize;

        mySel.pointSize = y,

        myStops_0 = []; 

        for ( var s = 0 ; s < S; s++ )  myStops_0.push([myStops.alignment, myStops.leader, myStops.position]); 

        myStops.everyItem().remove(); 

        for ( var s = 0 ; s < S; s++ )  myStops.add({alignment: myStops_0[0], leader: myStops_0[1], position: myStops_0[2]/x*y});

    }

(^/)

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