I have a textbox which the user clicks on in a form. This triggers the MouseUp event which runs a Do Loop, waiting for a users selection. The selection is any object in SolidWorks. After the object is selected, I have a sub that determines if there is a feature and verifies that it is the correct type of feature we're needing. Next, I exit the Loop. I then trigger, by code, the MouseUp event for that textbox so focus remains on it. I want the user to be able to select a different feature without having to click on the textbox again. I've got this code to work.
What I want to do now is keep my selection shown in SolidWorks but still enter into my Do While Loop so another selection can be made (if the user so chooses to).
The problem I'm running into is this:
After making a selection for the first time, there will always be a selected object. If I'm doing GetSelectedObject(1,-1), then my code will never see a different selection made because it will always pick the already selected object; the object that was selected the first time. I want to keep my selection visible until I make a new selection.
How do I keep my selection in the graphics view while still being able to select a different feature?
Private Sub featTxtBox_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
'Selection needs to be cleared in order for the Do Loop to run,
'but I would still like to have the previously found valid object (if any) selected in 'the graphics view until a new selection is made
swModel.ClearSelection2 True
Do While swSelmgr.GetSelectedObjectCount < 1 'if there hasn't been a selection made yet, 'still loop
DoEvents
Set vSel = swSelmgr.GetSelectedObject6(1, -1) 'set the variable to the selection
If Not vSel Is Nothing Then 'if there has been a selection, then process it
'GetFeatSelection takes vSel and determines what type of object it is.
'The object needed displayed for this textbox is a feature, which could be selected 'by one of it's edges (object type 1), faces (object type 2), or by selecting the 'feature (object type 22) itself from the feature tree.
'If an edge or face is selected then GetFeatSelection determines who the owning 'parent is (which will be the feature that was intended to be selected).
'If the object type is not 1, 2, or 22....then the object is not a valid selection, 'set validSel = False and exit GetFeatSelection sub; Do Loop repeats again for a new 'selection.
GetSelections.GetFeatSelection vSel
If validSel = True Then 'if the selected object is a valid selection, display 'information
featTxtBox.Text = patternFeat.Name
termfeatTxtBox.BackColor = RGB(255, 255, 255)
termfeatTxtBox.Enabled = True
termfeatTxtBox.Text = txtboxStr
patternFeat.Select True 'selects the feature in the SolidWorks graphics window 'to visually show the selection
SelText featTxtBox, False, "select" 'highlight the name of the selection to 'visually show a change in the userform
Exit Do
End If
End If
Loop
'trigger a MouseUp event for featTxtBox to return focus to it so the user can make a 'different selection (if they want)
'without having to click in the textbox again.
featTxtBox_MouseUp 1, 0, x, y
End Sub
SolidworksApi/macros