Why can't adding items into a new group?

Discussion in 'AutoCAD' started by anttam, Mar 6, 2005.

  1. anttam

    anttam Guest

    I want to group circle with radius =5 from the existing group called "c", but when excute
    "addGroup.AppendItems addEnt"
    an error message is showed
    Err : Method 'AppendItems' of object 'IAcadGroup' failed

    Why I such method failed? Where is the problem?

    Public Sub TestGroup()
    Dim objGroup As AcadGroup
    Dim addGroup As AcadGroup
    Dim addEnt() As AcadEntity
    Dim objEnt As AcadEntity
    Dim showEnt As AcadEntity
    Dim strName As String
    Dim addName As String
    Dim ct As Integer
    Dim count As Integer
    Dim varCen As Variant

    On Error Resume Next
    With ThisDrawing.Utility

    ''get the existing group
    strName = "c"
    Set objGroup = ThisDrawing.Groups.Add(strName)

    ''add new group
    addName = "new"
    Set addGroup = ThisDrawing.Groups.Add(addName)

    ''resize the entity aray
    count = 0
    For ct = 0 To objGroup.count - 1
    Set objEnt = objGroup.Item(ct)
    If objEnt.Radius = 5 Then
    count = count + 1
    End If
    Next ct
    .Prompt vbCrLf & "count = " & count
    ReDim addEnt(count)

    ''copy entities to entity array
    count = -1
    For ct = 0 To objGroup.count - 1
    Set objEnt = objGroup.Item(ct)

    If objEnt.Radius = 5 Then
    count = count + 1
    Set addEnt(count) = objEnt
    If Err Then .Prompt vbCrLf & "Err set : " & Err.Description
    .Prompt vbCrLf & "#" & ct & " radius = " & objEnt.Radius
    End If
    Next ct

    .Prompt vbCrLf & "now in addEnt:"
    For ct = 0 To count
    varCen = addEnt(ct).Center
    .Prompt vbCrLf & "#" & ct & " radius = " & addEnt(ct).Radius & _
    " Center at " & varCen(0) & "," & varCen(1)
    Next ct

    '' group circle
    addGroup.AppendItems addEnt
    If Err Then .Prompt vbCrLf & "Err : " & Err.Description

    .Prompt vbCrLf & "Now in addEnt have: "
    For ct = 0 To count
    Set showEnt = addGroup.Item(ct)
    .Prompt vbCrLf & "#" & ct & " radius = " & showEnt.Radius
    Next ct

    End With

    End Sub
     
    anttam, Mar 6, 2005
    #1
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.