PickFirstSelectionSet
PickFirstSelectionSet
(OP)
Greetings,
I am trying to let the user click on an "AcDbText" object and then use a hot key (Ctrl + E) to execute the following code:
****Start Code****
Sub EditPieceMark()
Dim SelectedItem As AcadText
Dim SelectionSet As AcadSelectionSet
Dim ReturnPnt As Variant
Dim PieceMarkRef As String
Set SelectionSet = ThisDrawing.PickfirstSelectionSet
If SelectionSet(0).ObjectName = "AcDbText" Then
Set SelectedItem = SelectionSet(0)
PieceMarkRef = Left(SelectedItem, InStr(1, SelectedItem, " "))
PieceMarkRef = Right(PieceMarkRef, Len(PieceMarkRef) - 1)
Else
MsgBox "You have selected the wrong type of item for this operation", vbExclamation + vbOKOnly, "Non-Text Item Selected"
Exit Sub
End If
FormIdentifier = "Edit"
Load frmAddBOMPart(PieceMarkRef)
frmAddBOMPart.Show
End Sub
****End Code****
My problem is that whenever the user presses the hot key, it seems to deselect the item on the drawing so that the AcadSelectionSet.Count is always zero. This throws the following error: "Invalid argument index in Item". This occurs when the if statement is executed. Any help would be greatly appreciated.
I am trying to let the user click on an "AcDbText" object and then use a hot key (Ctrl + E) to execute the following code:
****Start Code****
Sub EditPieceMark()
Dim SelectedItem As AcadText
Dim SelectionSet As AcadSelectionSet
Dim ReturnPnt As Variant
Dim PieceMarkRef As String
Set SelectionSet = ThisDrawing.PickfirstSelectionSet
If SelectionSet(0).ObjectName = "AcDbText" Then
Set SelectedItem = SelectionSet(0)
PieceMarkRef = Left(SelectedItem, InStr(1, SelectedItem, " "))
PieceMarkRef = Right(PieceMarkRef, Len(PieceMarkRef) - 1)
Else
MsgBox "You have selected the wrong type of item for this operation", vbExclamation + vbOKOnly, "Non-Text Item Selected"
Exit Sub
End If
FormIdentifier = "Edit"
Load frmAddBOMPart(PieceMarkRef)
frmAddBOMPart.Show
End Sub
****End Code****
My problem is that whenever the user presses the hot key, it seems to deselect the item on the drawing so that the AcadSelectionSet.Count is always zero. This throws the following error: "Invalid argument index in Item". This occurs when the if statement is executed. Any help would be greatly appreciated.
RE: PickFirstSelectionSet
What version of autoCAD are you working in?
Kevin Petursson
RE: PickFirstSelectionSet
where "EditPieceMark" is the sub routine in the module. This was done as a Macro.
But it doesn't matter now. I found an answer. I simply changed the "Set SelectionSet = ThisDrawing.PickfirstSelectionSet" line to "Set SelectionSet = ThisDrawing.ActiveSelectionSet" and everything seems to work just fine. Thanks for your interest in this problem.