Hi @JadhavP1
The code I posted earlier gets stuck in a loop!
Even though it at first seems like inventor behaves as normal after you hit esc, some functionalities are blocked due to a lingering handler.
This code however should work 🙂
I make sure pnt is actually set to nothing when you terminate the interaction with esc and then i do a bit of clean-up setting the events to nothing.
Public Sub Main()
Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oStartVal As Integer = InputBox("Start value", "Set start value", 1)
Dim getPoint As New clsGetPoint
Dim pnt As Point2d
Do
pnt = getPoint.GetDrawingPoint("Click the desired location", MouseButtonEnum.kLeftMouseButton)
If Not pnt Is Nothing Then
oSheet.DrawingNotes.GeneralNotes.AddFitted(pnt, "#" & oStartVal)
oStartVal += 1
End If
Loop While Not pnt Is Nothing
getPoint.CleanUp
End Sub
Class clsGetPoint
Private WithEvents m_interaction As InteractionEvents
Private WithEvents m_mouse As MouseEvents
Private m_position As Point2d
Private m_button As MouseButtonEnum
Private m_continue As Boolean
Public Function GetDrawingPoint(Prompt As String, button As MouseButtonEnum) As Point2d
Dim ThisApplication As Inventor.Application = GetObject(Nothing, "Inventor.Application")
m_position = Nothing
m_button = button
m_interaction = ThisApplication.CommandManager.CreateInteractionEvents
m_mouse = m_interaction.MouseEvents
m_interaction.StatusBarText = Prompt
m_interaction.Start
m_continue = True
Do
ThisApplication.UserInterfaceManager.DoEvents
Loop While m_continue
m_interaction.Stop
GetDrawingPoint = m_position
End Function
Private Sub m_mouse_OnMouseClick(ByVal button As MouseButtonEnum, ByVal ShiftKeys As ShiftStateEnum, ByVal ModelPosition As Point, ByVal ViewPosition As Point2d, ByVal View As View) Handles m_mouse.OnMouseClick
Dim ThisApplication As Inventor.Application = GetObject(Nothing, "Inventor.Application")
If button = m_button Then
m_position = ThisApplication.TransientGeometry.CreatePoint2d(ModelPosition.X, ModelPosition.Y)
End If
m_continue = False
End Sub
Private Sub oInteraction_OnTerminate() Handles m_interaction.OnTerminate
m_continue = False
End Sub
Public Sub CleanUp
m_mouse = Nothing
m_interaction = Nothing
End Sub
End Class
I apologise if you had to restart inventor due to testing my previous code.