- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have some problem using the inventor commandmanager.pick method. Below is the code. (Attached my VBA userform). When the userform run, I will pick the QTY from the userform, then I have used pick method to pick the dimension). the 'Pick" method does not work well. Sometimes I could able to pick the dimension, but many times no. Also attached the class function also, if anything wrong in below code, please advice.
Option Explicit
Public txtQTY As String
Public Sub Add_PrefixQTY_To_Dim()
Dim oSelect As New clsSelect
On Error GoTo finish:
' Declare a variable and create a new instance of the select class.
frmAddPrefix.Show
txtQTY = frmAddPrefix.txtQTY
Do
Dim oDrawDoc As DrawingDocument
Dim oRefDoc As Document
Set oDrawDoc = thisapplication.ActiveDocument
' Call the Pick method of the clsSelect object and set the filter to pick any dimension.
Dim oDrawDim As DrawingDimension
'Filter out anything that is not a dimension
Set oDrawDim = oSelect.PickDim(kDrawingDimensionFilter)
Dim oStr As String
'Check to see if the text is already there
If InStr(oDrawDim.Text.FormattedText, "X") = 0 Then
' If "TYP" has not been added already, add it
oStr = txtQTY + " " + oDrawDim.Text.FormattedText
oDrawDim.Text.FormattedText = oStr
' If "TYP" has been added already, skip this dimension and continue selecting
ElseIf InStr(oDrawDim.Text.FormattedText, "X") <> 0 Then
Dim i As Integer
Dim Pos As Integer
Dim FindChar As String
Dim SearchString As String
SearchString = oDrawDim.Text.FormattedText
FindChar = "X"
For i = 1 To Len(SearchString)
If Mid(SearchString, i, 1) = FindChar Then
Pos = i
End If
Next i
Dim FindXPos As String
FindXPos = Replace(oDrawDim.Text.FormattedText, Mid(oDrawDim.Text.FormattedText, 1, Pos), txtQTY)
oStr = FindXPos
oDrawDim.Text.FormattedText = oStr
End If
Loop
finish:
Unload frmAddPrefix
End Sub
' Declare the event objects
Private WithEvents oInteraction As InteractionEvents
Private WithEvents oMouseEvents As MouseEvents
Private WithEvents oSelect As SelectEvents
' Declare a flag that's used to determine when selection stops.
Private bstillSelecting As Boolean
Public Function PickDim(filter As SelectionFilterEnum) As Object
' Initialize flag.
bstillSelecting = True
' Create an InteractionEvents object.
Set oInteraction = thisapplication.CommandManager.CreateInteractionEvents
' Define that we want select events rather than mouse events.
oInteraction.SelectionActive = True
Set oMouseEvents = oInteraction.MouseEvents
' Set a reference to the select events.
Set oSelect = oInteraction.SelectEvents
' Set the filter using the value passed in.
oSelect.AddSelectionFilter (kDrawingDimensionFilter)
' The InteractionEvents object.
oInteraction.start
' Loop until a selection is made.
Do While bstillSelecting
thisapplication.UserInterfaceManager.DoEvents
'System.Windows.Forms.Application.DoEvents
Loop
' Get the selected item. If more than one thing was selected,
' just get the first item and ignore the rest.
Dim oSelectedEnts As ObjectsEnumerator
Set oSelectedEnts = oSelect.SelectedEntities
If oSelectedEnts.Count > 0 Then
Set PickDim = oSelectedEnts.Item(1)
Else
Set PickDim = Nothing
End If
' Stop the InteractionEvents object.
oInteraction.Stop
' Clean up.
Set oSelect = Nothing
Set oInteraction = Nothing
End Function
Public Function Pick(filter As SelectionFilterEnum) As Object
' Initialize flag.
bstillSelecting = True
' Create an InteractionEvents object.
Set oInteraction = thisapplication.CommandManager.CreateInteractionEvents
' Define that we want select events rather than mouse events.
oInteraction.SelectionActive = True
' Set a reference to the select events.
Set oSelect = oInteraction.SelectEvents
' Set the filter using the value passed in.
oSelect.AddSelectionFilter filter
' The InteractionEvents object.
oInteraction.start
' Loop until a selection is made.
Do While bstillSelecting
thisapplication.UserInterfaceManager.DoEvents
'System.Windows.Forms.Application.DoEvents
Loop
' Get the selected item. If more than one thing was selected,
' just get the first item and ignore the rest.
Dim oSelectedEnts As ObjectsEnumerator
Set oSelectedEnts = oSelect.SelectedEntities
If oSelectedEnts.Count > 0 Then
Set Pick = oSelectedEnts.Item(1)
Else
Set Pick = Nothing
End If
' Stop the InteractionEvents object.
oInteraction.Stop
' Clean up.
Set oSelect = Nothing
Set oInteraction = Nothing
End Function
Private Sub oInteraction_OnTerminate()
' Set the flag to indicate we're done.
bstillSelecting = False
End Sub
Private Sub oSelect_OnSelect(ByVal JustSelectedEntities As ObjectsEnumerator, _
ByVal SelectionDevice As SelectionDeviceEnum, _
ByVal ModelPosition As Point, _
ByVal ViewPosition As Point2d, _
ByVal View As View)
' Set the flag to indicate we're done.
bstillSelecting = False
End Sub
Solved! Go to Solution.