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();
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
...
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);
}
}
Copy link to clipboard
Copied
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...