Hello,
I wrote in "Microsstation V8i SS3" the following VBA code:
Option ExplicitImplements IPrimitiveCommandEventsPrivate nPunten As LongPrivate hoek As DoublePrivate Afst As DoublePrivate AfstV As DoublePrivate strAfst As StringPrivate Tekst As TextElementPrivate Lijn As LineElementPrivate SPoint(1) As Point3dPrivate Tpoint(1) As Point3dPrivate PPoint As Point3dPrivate Vect As Vector3dPrivate Rotatie As Matrix3d
Private Sub IPrimitiveCommandEvents_Cleanup() EndEnd 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 IfEnd 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 IfEnd Sub
Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String)
End Sub
Private Sub IPrimitiveCommandEvents_Reset() EndEnd 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
Now i'm trying to use this in "Microstation Connect" but 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 in 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
Hi Werner,
please, respect this forum Best Practices:
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Unknown said:Dim Axis As Point3d Axis.X = 0 Axis.Y = 0 Axis.Z = 1
Dim Axis As Point3d Axis = Point3dFromXYZ (0, 0, 1)
Is that clearer?
Unknown said:Vect.X = Tpoint(0).X - Tpoint(1).X Vect.Y = Tpoint(0).Y - Tpoint(1).Y Vect.Z = Tpoint(0).Z - Tpoint(1).Z
Vect = Point3dSubtract (Tpoint(0), Tpoint(1))
That's definitely clearer!
Unknown said: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
Not sure what that test is for! You want to scale Vect.X by Ls / AfstV? If Vect.X is zero then the result is zero: why test for non-zero?
Vect = Point3dScale (Vect, Ls / AfstV)
Regards, Jon Summers LA Solutions
Unknown said:Is there a way to remove this post?
Once a post has replies, one cannot remove it.
Unknown said:Can any of you remove this item?
Neither Jan nor I work for Bentley Systems. Only a Bentley Systems staff member who is a Forum moderator can remove a thread.