I tried a lot of way to do that,but still failed.
TextNode element has not got the width,height and font properties.
Who can help? Thanks.
I'm using this in my current project and it seems to work correctly.
private TextNodeElement createTextNodeElementWithStyle(_Application app_, ref Point3d point_, List<string> texts_, MicroStationDGN.Font font_, double height_, double width_)
{
//Save original settings
TextStyle
style = app_.ActiveSettings.TextStyle;
try
//Set settings for the creation of TextNode
app_.ActiveSettings.TextStyle.Width = width_; app_.ActiveSettings.TextStyle.Height = height_; app_.ActiveSettings.TextStyle.Font = font_;
app_.ActiveSettings.TextStyle.Width = width_;
app_.ActiveSettings.TextStyle.Height = height_;
app_.ActiveSettings.TextStyle.Font = font_;
Matrix3d matrix = app_.Matrix3dIdentity();
TextNodeElement textNode = app_.CreateTextNodeElement1(null, ref point_, ref matrix);
foreach (string text in texts_) { textNode.AddTextLine(text); }
textNode.AddTextLine(text);
}
return textNode; }
finally
//reset original settings
app_.ActiveSettings.TextStyle = style; } }
app_.ActiveSettings.TextStyle = style;
Unknown said:MDL provides the required functions. They are not exposed by VBA.
I suspected so. Thank you for the confirmation.
E.Jamster: TextNodeElement also has formatting properties, even when there is no text in it
True, but the TextElements contained by that TextNodeElement are free to have their individual formatting. The original question is how to modify the contained text elements, not how to apply a text style to a TextNodeElement.
E.Jamster: Is it some deprecated feature of DGN V7 that is deliberately made inaccessible?
If it were a deprecated feature of V7, you would not see it in the user interface.
E.Jamster: how to reach these properties through the Microstation API
MDL provides the required functions. They are not exposed by VBA.
Regards, Jon Summers LA Solutions
Unknown said:A TextNodeElement is not a TextElement. A TextNodeElement is a container of TextElements. TextElements have properties concerning appearance and contain the text that you see in graphics.
TextNodeElement also has formatting properties, even when there is no text in it.
Just add a new text node in the GUI, then look at its Element properties,When one adds some text to the textnode, these properties are inherited, but the text node still has a sepate formatting - one can inspect the file with OpenDGN to see that.
So the remaining question is how to reach these properties through the Microstation API.Or is it some deprecated feature of DGN V7 that is deliberately made inaccessible?
spike: Am I right?
Am I right?
You are not... Unfortunately, you can't modify TextElements inside of TextNodeElement until it is added into model...
This is explanation from help about GetSubelements:
When a program uses the Current property of an ElementEnumerator that GetSubElements returned, it gets a copy of the element. Changes to this element do not affect the contents of the ElementEnumerator or the contents of the ComplexElement. If the program changes this copy and saves it to the DesigFile, the next time the program accesses the element from the DesignFile the ComplexElement will have the changed components.
Sub main() Dim txtNd As TextNodeElement Dim oTextEnum As ElementEnumerator Dim txt As TextElement Set txtNd = CreateTextNodeElement1(Nothing, Point3dFromXY(0, 0), Matrix3dIdentity) txtNd.AddTextLine ("aaa") txtNd.AddTextLine ("bbb") ActiveModelReference.AddElement txtNd Set oTextEnum = txtNd.GetSubElements Do While oTextEnum.MoveNext Set txt = oTextEnum.Current txt.TextStyle.Color = 3 txt.TextStyle.Width = 10 txt.TextStyle.Height = 15 txt.TextStyle.Font = ActiveDesignFile.Fonts("Arial") txt.Rewrite Loop End Sub
txtNd is never redrawn.
AddElement should always be followed by a element.Redraw
Hi,Jon.
Actually,I did what you said like followings,but it still didn't work.
------------------------------------------------------------
Sub main()
Dim txtNd As TextNodeElement Dim oTextEnum As ElementEnumerator Dim txt As TextElement Set txtNd = CreateTextNodeElement1(Nothing, Point3dFromXY(0, 0), Matrix3dIdentity) txtNd.AddTextLine ("aaa") txtNd.AddTextLine ("bbb") Set oTextEnum = txtNd.GetSubElements Do While oTextEnum.MoveNext Set txt = oTextEnum.Current txt.TextStyle.Color = 3 txt.TextStyle.Width = 10 txt.TextStyle.Height = 15 txt.TextStyle.Font = ActiveDesignFile.Fonts("Arial") Loop ActiveModelReference.AddElement txtNd End Sub ------------------------------------------------------------ Am I right?
spike: TextNodeElement has not got the width, height or font properties.
TextNodeElement has not got the width, height or font properties.
A TextNodeElement is not a TextElement. A TextNodeElement is a container of TextElements. TextElements have properties concerning appearance and contain the text that you see in graphics.
You need to enumerate the TextElements contained in the TextNodeElement, and set the symbology for each TextElement that you find. Lookup GetSubElements in VBA help.
What I want to do is to create a textNode element and set it's size(width and height) and font,then add it to the dgn file.
So I can not use rewrite.
And when I create the textNode element by CreateTextNodeElement1(), I also tried to give an existed element to the first parameter of the method in order to initialize the properties of the textNode element. But that also didn't work.
Until now, what I know is that I can change a textNode element which was already added in dgn file by changing it's properties
and rewriting it.
So how should I do if I want to change a textNode element's properties before adding it to dgn file?
I do not know what u have tried but for example the font is set throu the Textstyle object
Dim oFont As Font Dim textEl As TextElement Set oFont = ActiveDesignFile.Fonts.Find(msdFontTypeSHX, "Arial") set textEl.TextStyle.Font=oFont textEl.Redraw textEl.Rewrite
This should work I think