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: Method 'Item' of object 'IAcadSelectionSet'
    failed

    How should I get around with this problem? Is there an alternative?

    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(3) As Integer
    Dim avFilterValues(3) As Variant
    Dim nCur As Integer
    Dim objItem(100) As Object

    m_nTotalGrpPcInfo = 0

    On Error GoTo Err_SavePcInfoToArray

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

    anFilterTypes(0) = -4: avFilterValues(0) = "<or"
    anFilterTypes(1) = 8: avFilterValues(1) = "My_Flex"
    anFilterTypes(2) = 8: avFilterValues(2) = "My_Rect"
    anFilterTypes(3) = -4: avFilterValues(3) = "or>"
    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 loop through each item in the
    'selection set. But failed at Item() method.
    For nCur = 0 To objSelectSet.Count - 1
    Set objItem(nCur) = objSelectSet.Item(nCur)
    Next nCur

    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

    Thanks in advance for any help.

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

    Jay Chan Guest

    I change the loop to something like this, but it still doesn't work:

    Dim objItem As AcadEntity
     
    Jay Chan, Dec 27, 2006
    #2
  3. Jay Chan

    Jay Chan Guest

    Turns out this problem has something to do with the fact that those
    items are drawn using CAD-Duct (a third party software running on top
    of AutoCAD). 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. I will
    have to use the combination of VisualLISP and a Scripting API that
    CAD-Duct has offered as an option (for additional $$$).

    Jay Chan
     
    Jay Chan, Jan 2, 2007
    #3
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.