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

Set Font Size, Font Color and Font Name for a NewTexLine

Explorer ,
Dec 01, 2023 Dec 01, 2023

Copy link to clipboard

Copied

Hello,

I am trying to create a new text line on a graphic frame.
The line is created corretly, in the correct position and with the correct text.
But I cannot see any option to set the font size, the font color and font name for this content.

This is what I tried so far:

 

var graphic = null;
var doc = app.ActiveDoc;
graphic = doc.FirstSelectedGraphicInDoc;
var frameParent = graphic.FrameParent;

var textLineObj = doc.NewTextLine(frameParent);

textLineObj.LocX = 20 * MM;
textLineObj.LocY = 50 * MM;

var textLocation = new TextLoc(textLineObj, 0);
doc.AddText(textLocation, "Hello World");
textLineObj.Width = 30 * MM;
textLineObj.Height = 10 * MM;
textLineObj.Color = Constants.FV_COLOR_BLACK;
textLineObj.Fill = Constants.FV_FILL_BLACK;

doc.Redisplay();

 

TOPICS
Formatting and numbering , Scripting

Views

96

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 , Dec 01, 2023 Dec 01, 2023

I suggest that you apply a named character format instead of setting individual font properties. This will allow you to make global changes later.

 

#target framemaker

var doc, textline, textRange;

doc = app.ActiveDoc;

// Make sure the text line is selected.
textline = doc.FirstSelectedGraphicInDoc;

// Select the text.
textRange = new TextRange (
    new TextLoc (textline, 0),
    new TextLoc (textline, Constants.FV_OBJ_END_OFFSET)
);

// Call a function to apply a character format.
applyCha
...

Votes

Translate

Translate
Community Expert ,
Dec 01, 2023 Dec 01, 2023

Copy link to clipboard

Copied

I suggest that you apply a named character format instead of setting individual font properties. This will allow you to make global changes later.

 

#target framemaker

var doc, textline, textRange;

doc = app.ActiveDoc;

// Make sure the text line is selected.
textline = doc.FirstSelectedGraphicInDoc;

// Select the text.
textRange = new TextRange (
    new TextLoc (textline, 0),
    new TextLoc (textline, Constants.FV_OBJ_END_OFFSET)
);

// Call a function to apply a character format.
applyCharFmt (textRange, "Emphasis", doc);

function applyCharFmt (textRange, name, doc) {
    
    var charFmt, prop;
    
    charFmt = doc.GetNamedCharFmt (name);
    if (charFmt.ObjectValid () === 1) {
        doc.SetTextProps (textRange, charFmt.GetProps ());
    }
    else {
        prop = new PropVal ();
        prop.propIdent.num = Constants.FP_CharTag;
        prop.propVal.valType = Constants.FT_String;
        prop.propVal.sval = name;
        doc.SetTextPropVal (textRange, prop);
    }
}

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
Explorer ,
Dec 03, 2023 Dec 03, 2023

Copy link to clipboard

Copied

LATEST

Thanks, that worked.

So we need to use textRange to be able to format the text on a textLine.
A bit confusing, textRange for formatting, textLoc for adding the text to the doc, textLine for some other settings...

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