Hello,
I wrote in "Microsstation V8i SS3" the VBA code below.
Now i'm trying to use this VBA code in "Microstation Connect" but, when running the vba, the origin of the textelement is not right.
The text is on a different coordinate than the original point.
when I do not use the rotation matrix, the text on the right place.
I also tried different matrixes like "Matrix3dFromVectorAndRotationAngle" and "Matrix3dRotationFromColumnZ" but the result is the same.
Does anyone know what here is going on?
kind regards,
Werner
The code of Class Module : PlaceTekstAfst
Option Explicit, Implements IPrimitiveCommandEvents Private nPunten As Long Private hoek As Double Private Afst As Double Private AfstV As Double Private strAfst As String Private Tekst As TextElement Private Lijn As LineElement Private SPoint(1) As Point3d Private Tpoint(1) As Point3d Private PPoint As Point3d Private Vect As Vector3d Private Rotatie As Matrix3d Private Sub IPrimitiveCommandEvents_Cleanup() End End Sub Private Sub IPrimitiveCommandEvents_DataPoint(point As Point3d, ByVal View As View) If nPunten = 0 Then SPoint(0) = point nPunten = 1 ShowPrompt "enter eindpunt/esc om te stoppen" CommandState.StartDynamics ElseIf nPunten = 1 Then SPoint(1) = point If TekstAfstand.OBAASelectie.Value = True Then If SPoint(0).X = SPoint(1).X Then hoek = Pi / 2 Else hoek = Atn((SPoint(0).Y - SPoint(1).Y) / (SPoint(0).X - SPoint(1).X)) End If ElseIf TekstAfstand.OBAA0.Value = True Then hoek = 0 ElseIf TekstAfstand.OBAA90.Value = True Then hoek = Pi / 2 End If Dim Axis As Point3d Axis.X = 0 Axis.Y = 0 Axis.Z = 1 Rotatie = Matrix3dFromVectorAndRotationAngle(Axis, hoek) Afst = Point3dDistance(SPoint(0), SPoint(1)) strAfst = Str(Round(Afst, 3)) ShowPrompt "Place distance /esc to quit" nPunten = 2 ElseIf nPunten = 2 Then PPoint = point If ULs = True Then 'calculation linespacing Tpoint(0) = point Tpoint(1) = Lijn.ProjectPointOnPerpendicular(point, Matrix3dIdentity) Vect.X = Tpoint(0).X - Tpoint(1).X Vect.Y = Tpoint(0).Y - Tpoint(1).Y Vect.Z = Tpoint(0).Z - Tpoint(1).Z AfstV = Point3dDistanceXY(Tpoint(1), Tpoint(0)) If Vect.X <> 0 Then Vect.X = (Vect.X / AfstV) * Ls If Vect.Y <> 0 Then Vect.Y = (Vect.Y / AfstV) * Ls If Vect.Z <> 0 Then Vect.Z = (Vect.Y / AfstV) * Ls PPoint = Point3dAddPoint3dVector3d(Tpoint(1), Vect) End If Set Tekst = CreateTextElement1(Nothing, strAfst, PPoint, Rotatie) ActiveModelReference.AddElement Tekst Tekst.Redraw CommandState.StartPrimitive New PlaceTekstAfst End If End Sub Private Sub IPrimitiveCommandEvents_Dynamics(point As Point3d, ByVal View As View, ByVal DrawMode As MsdDrawingMode) If nPunten = 1 Then Set Lijn = CreateLineElement2(Nothing, SPoint(0), point) Lijn.Redraw DrawMode Dim PNormal As Point3d PNormal = Point3dSubtract(Lijn.EndPoint, Lijn.StartPoint) Set Tekst = CreateTextElement1(Nothing, Str(Round(Point3dDistance(SPoint(0), point), 3)), point, Matrix3dRotationFromColumnZ(PNormal)) Tekst.Redraw DrawMode ElseIf nPunten = 2 Then ModOmvormen.Text PPoint = point If ULs = True Then 'calculation linespacing Tpoint(0) = point Tpoint(1) = Lijn.ProjectPointOnPerpendicular(point, Matrix3dIdentity) Vect.X = Tpoint(0).X - Tpoint(1).X Vect.Y = Tpoint(0).Y - Tpoint(1).Y Vect.Z = Tpoint(0).Z - Tpoint(1).Z AfstV = Point3dDistanceXY(Tpoint(1), Tpoint(0)) If Vect.X <> 0 Then Vect.X = (Vect.X / AfstV) * Ls If Vect.Y <> 0 Then Vect.Y = (Vect.Y / AfstV) * Ls If Vect.Z <> 0 Then Vect.Z = (Vect.Y / AfstV) * Ls PPoint = Point3dAddPoint3dVector3d(Tpoint(1), Vect) End If Set Tekst = CreateTextElement1(Nothing, strAfst, PPoint, Rotatie) Tekst.Redraw DrawMode End If End Sub Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String) End Sub Private Sub IPrimitiveCommandEvents_Reset() End End Sub Sub IPrimitiveCommandEvents_Start() Dim lc As LocateCriteria Set lc = CommandState.CreateLocateCriteria(False) nPunten = 0 CommandState.SetLocateCriteria lc CommandState.EnableAccuSnap ShowCommand "Place distance" ShowPrompt "enter first point /esc to quit" End Sub
Hi,
I have tried to understand what exactly happens, but a couple of variables are not defined within the code snipped, so it´s a lot of assuming.So I tried to reduce the problem and created my own code example using your approach trying to simulate the situation:
Dim hoek As Double Dim Rotatie As Matrix3d Dim Axis As Point3d Dim oText As TextElement Axis.X = 0 Axis.Y = 0 Axis.Z = 1 hoek = Atn(0.5) ' arbitrary angle: 26.565051177078° rotation Rotatie = Matrix3dFromVectorAndRotationAngle(Axis, hoek) Set oText = CreateTextElement1(Nothing, "hello", Point3dZero, Rotatie) ActiveModelReference.AddElement oText
And tested this in both V8i SS4 and Connect Upd2. The result was in both releases the same and correct. The text is rotated around the origin of the text.Do you get different results with this code example?
If this doesn´t help to explain the issue, could you please upload a complete example to allow us to reproduce this issue?
ThanksArtur
I use the latest version of MicroStation
If it works whit you, there must be an other reason.
Since the routine work for you, the cause must lie elsewhere.
For testing all off my routines I use the same dgn-file.
And I don't use textstyle for testing this.
Screenshots whit MS V8i:
Settings text
Result using the routine:
Now for MC Connect: settings text and result using routine
Regards,
Please find the dgn I use to test the routine here: www.filedropper.com/woningachtermaal
thank you for submitting the DGN file. I was able to reproduce the issue you reported using this DGN file.I have also reduced the VBA code to this minimum text creation example without rotation:
Dim oText As TextElement Set oText = CreateTextElement1(Nothing, "hello", Point3dZero, Matrix3dIdentity) ActiveModelReference.AddElement oText Debug.Print oText.Origin.X, oText.Origin.Y
Using this code I got this shifted text origin:
x:-3622922.73246951 y:1249875
So far I was not able to detect a setting responsible for this shift, ACS, GCS or GO are not the reason.I will let you know about new findings.
Best regards,Artur