Hi,Is there a possibility in C# to set a different justification (e.g. from Left Buttom to Center Center) for an already placed text without moving the text?
With the following code, the text is unfortunately moved.
using BD = Bentley.DgnPlatformNET; using BDE = Bentley.DgnPlatformNET.Elements; using BG = Bentley.GeometryNET; using BIM = Bentley.Interop.MicroStationDGN; using BM = Bentley.MstnPlatformNET; using BMI = Bentley.MstnPlatformNET.InteropServices; ... // element is a BDE-Element ... BIM.Element elementBim = BMI.Utilities.ComApp.ActiveModelReference.GetElementByID(element.ElementId); if (elementBim.IsTextElement()) { // Change the Justification from Left Buttom to Center Center elementBim.AsTextElement().TextStyle.Justification = BIM.MsdTextJustification.CenterCenter; elementBim.Rewrite(); } ...
Before:
After:
I am afraid that I think this is too simple.
Regards,Frank
HI Frank,
I see you use old Interop API (so VBA API in fact), not new CE NET API. I recall some changes (CE vs V8i) and bugs (in CE implementation) were discussed about how text origin is managed by user tools and API.
In my opinion the described behavior is correct, because when you change the justification, without chaning the origin coordinates, the move moves. I assume, when you want to fix the text position, you must move the text by yourself after the justification is changed.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan,thanks.With this, it worked:
if (elementBim.IsTextElement()) { BIM.Point3d offset; var urRangeLow = elementBim.AsTextElement().Range.Low; elementBim.AsTextElement().TextStyle.Justification = BIM.MsdTextJustification.CenterCenter; var neuRangeLow = elementBim.AsTextElement().Range.Low; offset.X = urRangeLow.X - neuRangeLow.X; offset.Y = urRangeLow.Y - neuRangeLow.Y; offset.Z = urRangeLow.Z - neuRangeLow.Z; elementBim.AsTextElement().Move(offset); elementBim.Rewrite(); }
Frank