Erased 3dSolid Not Nothing?

Discussion in 'AutoCAD' started by D Hartley, Apr 30, 2004.

  1. D Hartley

    D Hartley Guest

    I sometimes get the error message "Object has been erased", occuring on the
    acSubtraction operation

    I thought the " If Not X Is Nothing" would test for this
    What am I missing?

    Dim XSolid As New Collection
    Dim NewSolid As Acad3DSolid

    For c = 1 To XSolid.Count
    If Not XSolid(c) Is Nothing And Not NewSolid Is NothingThen
    XSolid(c).Boolean acSubtraction, NewSolid
    End If
    Next c

    Thank you kindly
    David
     
    D Hartley, Apr 30, 2004
    #1
  2. D Hartley

    Perion Guest

    Have you tried using the For/Each mechanism for iterating the collection?

    If object.count > 0 Then
    For Each object In ObjectsCollection
    ' do something with the object.
    Next [ object ]
    End If

    Perion
     
    Perion, Apr 30, 2004
    #2
  3. D Hartley

    Perion Guest

    Typo - my bad!
    Not "object.count".


    If ObjectsCollection.count > 0 Then
    For Each object In ObjectsCollection
    ' do something with the object.
    Next [ object ]
    End If
     
    Perion, Apr 30, 2004
    #3
  4. D Hartley

    D Hartley Guest

    I think I found my own answer- am posting it here in case somebody else has
    the same problem


    From the VBA help files:
    Note: Do not use the entity edit methods (Copy, Array, Mirror, and so forth)
    on any object while simultaneously iterating through a collection using the
    For Each mechanism. Either finish your iteration before you attempt to edit
    an object in the collection or create a temporary array and set it equal to
    the collection. Then you can iterate through the copied array and perform
    your edits.

    David
     
    D Hartley, May 1, 2004
    #4
  5. D Hartley

    wivory Guest

    Your assumption is incorrect. Just deleting an object is not enough to set the object reference to Nothing - you must explicitly do so.

    [pre]
    XSolid(c).Delete
    Set XSolid(c) = Nothing
    [/pre]

    It would be nice if it worked automatically - I've been caught that way myself.

    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, May 3, 2004
    #5
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.