Fail to Loop Through Items in a SelectionSet

Discussion in 'AutoCAD' started by Jay Chan, Dec 27, 2006.

  1. Jay Chan

    Jay Chan Guest

    I am trying to use VBA to loop through all the items in a selection-set
    to find their patterns. Unfortunately, I keep getting the following
    error message when I use Item() method of the selection-set to try to
    get acess to an item in the selection-set:
    Error Number: -2147418113
    Error Description: Automation error Catastrophic failure

    The following is a sample program that shows the error:

    Private Sub SavePcInfoToArray()
    'Save the info of all the pieces into an array.

    Dim objSelectSet As AcadSelectionSet
    Dim anFilterTypes(0) As Integer
    Dim avFilterValues(0) As Variant
    Dim nCur As Integer
    Dim objItem As AcadEntity

    On Error GoTo Err_SavePcInfoToArray

    Set objSelectSet = ThisDrawing.SelectionSets.Add("AllPcs")

    anFilterTypes(0) = 8
    avFilterValues(0) = "My_Rect"
    objSelectSet.Select acSelectionSetAll, , , _
    anFilterTypes, avFilterValues

    'Here, the program shows the correct number of
    'items selected. So far so good.
    ThisDrawing.Utility.Prompt vbCrLf & _
    "Total Pieces Selected: " & objSelectSet.Count

    'Trying to get access to the three items in the
    'selection set. But failed at Item() method.
    If (objSelectSet.Count = 3) Then
    Set objItem = objSelectSet.Item(0) <-- Fail right here
    Set objItem = objSelectSet.Item(1)
    Set objItem = objSelectSet.Item(2)
    End If

    objSelectSet.Delete
    Exit Sub

    Err_SavePcInfoToArray:
    If (Not objSelectSet Is Nothing) Then
    objSelectSet.Delete
    End If
    MsgBox "Error # " & Err.Number & ": " & Err.Description
    Exit Sub
    End Sub

    I am wondering whether this may have something to do with the fact that
    I use a third party software called CAD-Duct to add those three items
    onto the drawing. The reason why I have this suspicion is that the
    same program can get access to a generic rectangle that I use plain
    AutoCAD graphic to draw it instead of using CAD-Duct -- meaning that
    the generic rectangle becomes the Item(0) of the selection-set. The
    result is like this:

    If (objSelectSet.Count = 4) Then
    Set objItem = objSelectSet.Item(0) <-- It is OK
    Set objItem = objSelectSet.Item(1) <-- Fail right here
    Set objItem = objSelectSet.Item(2)
    Set objItem = objSelectSet.Item(4)
    End If

    Seem like somehow the three items that I draw using CAD-Duct becomes
    hidden when I use Item() method to try to get access to it. How can I
    get around with this problem?

    Thanks in advance for any help.

    Jay Chan
     
    Jay Chan, Dec 27, 2006
    #1
  2. Jay Chan

    Jay Chan Guest

    Turns out the properties of the items that are drawn using CAD-Duct is
    in a different format than regular generic items that are drawn using
    pure AutoCAD. That explains the reason why I cannot use Item() method
    to get access to the properties of the items drawn using CAD-Duct.

    Based on some past posts in a different forum, I am supposed to be able
    to get around with this problem by installing something called Object
    Enabler that I can download from CAD-Duct web site. Unfortunately,
    that Object Enabler trick doesn't work in AutoCAD 2007 that I am
    currently using. In other words, this is yet another deadend.

    The bottom line is that I cannot use VBA to get access to properties of
    items drawn by CAD-Duct as long as I am using AutoCAD 2007.

    Hope this info helps something to avoid the pitfall.

    Jay Chan
     
    Jay Chan, Jan 2, 2007
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.