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

applying fcode to a text range?

Community Expert ,
Jan 02, 2015 Jan 02, 2015

Copy link to clipboard

Copied

Hi all,

I'm trying to apply an fcode to a text range.

If I manually select text, this code makes the text bold:

fcodes = new Array();

fcodes[0] = FCodes.TXT_BOLD;

Fcodes(fcodes);

However, if I try to programmatically select the text, the fcode has no effect:

var tr = new TextRange (); 

tr.beg.obj = tr.end.obj = pgf; 

tr.beg.offset = 0; 

tr.end.offset = 5;

fcodes = new Array();

fcodes[0] = FCodes.TXT_BOLD;

Fcodes(fcodes);

I fear I'm missing something simple or obvious. Must my code explicitly toggle the text range as "selected"?

-Alan

TOPICS
Scripting

Views

637

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 02, 2015 Jan 02, 2015

I am not a big fan of Fcodes and rarely use them in my scripts. They only work on the active document and there are usually better, more reliable ways of accomplishing things. For example, here is how you can use code to apply a Bold character format to a text range, assuming that the "Bold" character format exists in the active document. The nice thing is that the applyCharFmt function could be used in any script and will always work the same way. And you can pass it any valid text range, even

...

Votes

Translate

Translate
Community Expert ,
Jan 02, 2015 Jan 02, 2015

Copy link to clipboard

Copied

Hi Alan,

Yes, FCodes work on the active document and mimic what you do interactively. So to use this FCode, you need to actually have the text selected. You should be able to add this before the Fcodes(fcodes) command:

app.ActiveDoc.TextSelection = tr;

Please let me know if you have any questions or comments.

Rick

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 02, 2015 Jan 02, 2015

Copy link to clipboard

Copied

I am not a big fan of Fcodes and rarely use them in my scripts. They only work on the active document and there are usually better, more reliable ways of accomplishing things. For example, here is how you can use code to apply a Bold character format to a text range, assuming that the "Bold" character format exists in the active document. The nice thing is that the applyCharFmt function could be used in any script and will always work the same way. And you can pass it any valid text range, even in an invisible document.

#target framemaker

// Get the active document.

var doc = app.ActiveDoc;

// Get the paragraph containing the insertion point.

var pgf = doc.TextSelection.beg.obj;

// Make a text range.

var tr = new TextRange ();

tr.beg.obj = tr.end.obj = pgf;

tr.beg.offset = 0;

tr.end.offset = 5;

// Apply the Bold character format.

applyCharFmt (tr, "Bold", doc);

function applyCharFmt (textRange, name, doc) {

   

    var charFmt = 0;

   

    charFmt = doc.GetNamedCharFmt (name);

    if (charFmt.ObjectValid()) {

        doc.SetTextProps (textRange, charFmt.GetProps());

    }

}

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 02, 2015 Jan 02, 2015

Copy link to clipboard

Copied

Thanks, Rick. Setting the text selection via "app.ActiveDoc.TextSelection = tr;" was what I needed.

Apologies ... I pulled the "bold" example out of the air. I actually want to invoke the Init Caps operation, presented by the GUI in the Text Formatting toolbar.

I think it's defensible to use the fcode for this (I'm changing character case, not properties), although I may need to drop back and do it by regular expression.

Now that I've gotten this far, "TXT_INITCAPS" (the apparent fcode for this operation, from fcodes.h) has no effect, on a manually or programmatically-selected text range.

If anybody has any insight into why TXT_INITCAPS has no effect, I would be grateful.

-Alan

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 02, 2015 Jan 02, 2015

Copy link to clipboard

Copied

Hi Alan, Here is the FCode you need: KBD_INITCAP. -Rick

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 02, 2015 Jan 02, 2015

Copy link to clipboard

Copied

Wow ... thank you!

Did you know that by other than finding it in fcodes.h and trying it?

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 02, 2015 Jan 02, 2015

Copy link to clipboard

Copied

LATEST

Believe it or not, I looked in the FrameScript reference manual. I searched on "cap" and located it.

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