Highlighted

How to center the new string ?

Community Beginner ,
Oct 02, 2018

Copy link to clipboard

Copied

Hi forum.

I have got a function that delete a text from a texline  and set a new text in this one.

the new text is shorter and i would to center this text instead of set on the left side.

the currently uggly workaround i found is to put space to the front of the new text.

do you have smarter solution to center the text like managing the offset,LocX or adding the center property .

thank you

function ChangeText(TextLineFrame){

    // cette procedure remplace le texte de l'objet TEXTLINE

    // on défini le textrange

    // on recupére les proprietés du texte avant de le supprimer et de le remplacer.

  

     var DZGprops  

     var BegLoc = new TextLoc(), EndLoc = new TextLoc(); //create text location object

           

     BegLoc.obj = TextLineFrame;

     BegLoc.offset = 0; // insert at the start of the cell

     EndLoc.obj=TextLineFrame;

     EndLoc.offset=Constants.FV_OBJ_END_OFFSET;

    var textRange = new TextRange (BegLoc, EndLoc);

  

    DZGprops= app.ActiveDoc.GetTextProps(textRange.beg);

    app.ActiveDoc.DeleteText(textRange);

    app.ActiveDoc.AddText(BegLoc, "                                                    new text with front blank space"  );

    app.ActiveDoc.SetTextProps(textRange, DZGprops);  

    $.writeln("text has been change");

  

     }

Hi,

Sometimes formatting rules/properties do not re-apply fully when you alter a document. I suspect that when you toggle the page view, it is reapplying formatting properties and that is why the problem gets fixed. You might also consider trying a forced refresh, something like:

oDoc.Reformat()

and/or

oDoc.Redisplay()

Theoretically, these should not be necessary, but sometimes for unknown reasons they are.

Russ

TOPICS
Scripting

Views

231

Likes

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

How to center the new string ?

Community Beginner ,
Oct 02, 2018

Copy link to clipboard

Copied

Hi forum.

I have got a function that delete a text from a texline  and set a new text in this one.

the new text is shorter and i would to center this text instead of set on the left side.

the currently uggly workaround i found is to put space to the front of the new text.

do you have smarter solution to center the text like managing the offset,LocX or adding the center property .

thank you

function ChangeText(TextLineFrame){

    // cette procedure remplace le texte de l'objet TEXTLINE

    // on défini le textrange

    // on recupére les proprietés du texte avant de le supprimer et de le remplacer.

  

     var DZGprops  

     var BegLoc = new TextLoc(), EndLoc = new TextLoc(); //create text location object

           

     BegLoc.obj = TextLineFrame;

     BegLoc.offset = 0; // insert at the start of the cell

     EndLoc.obj=TextLineFrame;

     EndLoc.offset=Constants.FV_OBJ_END_OFFSET;

    var textRange = new TextRange (BegLoc, EndLoc);

  

    DZGprops= app.ActiveDoc.GetTextProps(textRange.beg);

    app.ActiveDoc.DeleteText(textRange);

    app.ActiveDoc.AddText(BegLoc, "                                                    new text with front blank space"  );

    app.ActiveDoc.SetTextProps(textRange, DZGprops);  

    $.writeln("text has been change");

  

     }

Hi,

Sometimes formatting rules/properties do not re-apply fully when you alter a document. I suspect that when you toggle the page view, it is reapplying formatting properties and that is why the problem gets fixed. You might also consider trying a forced refresh, something like:

oDoc.Reformat()

and/or

oDoc.Redisplay()

Theoretically, these should not be necessary, but sometimes for unknown reasons they are.

Russ

TOPICS
Scripting

Views

232

Likes

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
Oct 02, 2018 0
Engaged ,
Oct 02, 2018

Copy link to clipboard

Copied

Hi,

TextLines have no alignment, so you need to reposition the textline object.

Possible Algorithm:

1. Get Position (LocX) and width of the original TextLineFrame

2. Change text

3. Get Position (LocX) and width of the new TextLineFrame

4. Reposition changed TextLineFrame

var newX = oldX + oldWidth - newWidth;

Hope this helps

Markus

Likes

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
Reply
Loading...
Oct 02, 2018 0
Adobe Community Professional ,
Oct 02, 2018

Copy link to clipboard

Copied

The alignment for a TextLine is controlled by its TextLineType property. Here are some of the values:

Constants.FV_TEXTLINE_LEFT

Constants.FV_TEXTLINE_CENTER

Constants.FV_TEXTLINE_RIGHT

Likes

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
Reply
Loading...
Oct 02, 2018 0
Community Beginner ,
Oct 02, 2018

Copy link to clipboard

Copied

Thank you for response.

As the textline is on reference page i found an other solution.i just swap between body page and reference page and the text is automatically centered in his textline. Why i don't know but it works.

the code become:.

function ChangeText(TextLineFrame){

    // cette procedure remplace le texte de l'objet TEXTLINE

    // on défini le textrange

    // on recupére les proprietés du texte avant de le supprimer et de le remplacer.

     var oDoc = app.ActiveDoc;

     var DZGprops   

     var BegLoc = new TextLoc(), EndLoc = new TextLoc(); //create text location object

            

     BegLoc.obj = TextLineFrame;

     BegLoc.offset = 0; // insert at the start of the cell

     EndLoc.obj=TextLineFrame;

     EndLoc.offset=Constants.FV_OBJ_END_OFFSET;

    var textRange = new TextRange (BegLoc, EndLoc);

   

    DZGprops= app.ActiveDoc.GetTextProps(textRange.beg);

    app.ActiveDoc.DeleteText(textRange);

    app.ActiveDoc.AddText(BegLoc, "new text to insert"  );

     //TextLineFrame=Constants.FV_TEXTLINE_CENTER;

    app.ActiveDoc.SetTextProps(textRange, DZGprops);   

  

    // il faut switcher les pages pour que le nouveau texte soit centré pourquoi ????

     // switch body page and ref page to display the text centered ????

    oDoc.CurrentPage = oDoc.FirstBodyPageInDoc;

    oDoc.CurrentPage = oDoc.FirstRefPageInDoc;

    $.writeln("Le copyright à été changé");

   

     }

Likes

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
Reply
Loading...
Oct 02, 2018 0
Mentor ,
Oct 02, 2018

Copy link to clipboard

Copied

Hi,

Sometimes formatting rules/properties do not re-apply fully when you alter a document. I suspect that when you toggle the page view, it is reapplying formatting properties and that is why the problem gets fixed. You might also consider trying a forced refresh, something like:

oDoc.Reformat()

and/or

oDoc.Redisplay()

Theoretically, these should not be necessary, but sometimes for unknown reasons they are.

Russ

Likes

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
Reply
Loading...
Oct 02, 2018 0