Hi Alfred,
Here is the code I use
Public Shared Function GetAngleAtPointOnLine() As AngleAtPointOnLineClass
Dim retValue As New AngleAtPointOnLineClass
Try
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim myEd As Editor = acDoc.Editor
Dim bObject As New PromptNestedEntityOptions("")
Dim opt As PromptPointOptions = New PromptPointOptions("Select point on object: ")
bObject.NonInteractivePickPoint = myEd.GetPoint(opt).Value
bObject.UseNonInteractivePickPoint = True
Dim bRes As PromptNestedEntityResult = myEd.GetNestedEntity(bObject)
If bRes.Status = PromptStatus.OK Then
Using myTrans As Transaction = acDoc.TransactionManager.StartTransaction
'the return value of your nested selection may not always be one of
'those things that derives from curve, so you should check it first!
If bRes.ObjectId.ObjectClass.IsDerivedFrom(Curve.GetClass(GetType(Curve))) Then
Dim crv As Curve = myTrans.GetObject(bRes.ObjectId, OpenMode.ForRead, False, True)
Dim wcsPoint As Point3d = bRes.PickedPoint.TransformBy(myEd.CurrentUserCoordinateSystem)
Dim myFirstDerivative As Vector3d = crv.GetFirstDerivative(wcsPoint)
retValue.Angle = Math.Atan2(CDbl(myFirstDerivative.Y), CDbl(myFirstDerivative.X)) * (180 / Math.PI)
retValue.point = New Point3d(bRes.PickedPoint.X, bRes.PickedPoint.Y, bRes.PickedPoint.Z)
End If
End Using
End If
retValue.HasError = False
Catch ex As Exception
retValue.HasError = True
Debug.Print(ex.Message)
End Try
Return retValue
End Function
End Class
Public Class AngleAtPointOnLineClass
Public HasError As Boolean
Public Angle As Double
Public point As Point3d
End Class
I found parts of the code on internet. I more or less understand what is happening. As you can see the angle is derived from the exact location on the object. In WCS this function works fine. In UCS the point comes out correctly, but the angle not. The angle needs to be corrected to an angle in WCS.
Frank