Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here





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)
        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)
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 does you call to this code look like as assigned to ctrl+E?

What version of autoCAD are you working in?

Kevin Petursson

RE: PickFirstSelectionSet

I am working with AutoCAD 2006. My call to the ctrl+E looks like: (command "_-vbarun" "EditPieceMark")
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close