Is there a SelectionSet usage limit?

Discussion in 'AutoCAD' started by Mike Tuersley, Aug 5, 2004.

  1. This is weird, but has anyone heard of or come across a limit on the number
    of times a selectionset can be re-used? I've got a monster app written in
    VB.NET using COM INTEROP that creates wiring schematics based on
    information retrieved from a C# webmethod - it automates the drawing task
    in AutoCAD 2005.

    The program pops an error every time on the 37th pass. I've checked all the
    obvious things I can think of - yes, the blocks are valid, are actually
    inserted and haven't been erased as is reported in the error. I've also
    reordered my JOB so the 37th pass contains different blocks just to make
    sure. At this moment in the program, about 350-600 blocks have been insert
    into the sset [2 to 60 per loop] during the 36 previous passes and the sset
    is deleted before it starts the next loop. I've even tried clearing the
    sset instead of deleting it. Since the program is massive, here's just the
    portion in question:

    For lCntr = 1 To Job.Count
    'grab Component from JOB
    oComponent = Job.Item(lCntr)
    'create an AutoCAD Selection Set
    cadSSet = m_cadDoc.SelectionSets.Add("iDrawing")
    'insert graphic and set reference to blockref
    cadBRef = InsertComponent(oComponent)
    'add blockref to selectionset
    cadBRefs(0) = cadBRef
    cadSSet.AddItems(cadBRefs)
    'loop to insert all subcomponents
    For lCntr2 = 1 To oComponent.Item.Count
    'insert graphic and set reference to blockref
    cadBRef = InsertComponent(oComponent.Item(lCntr2))
    'add blockref to selectionset
    cadBRefs(0) = cadBRef
    cadSSet.AddItems(cadBRefs)
    Next

    'move into position, populate attributes, etc.
    'PASSING SelSet BYREF so it records update insertion points
    'ERROR OCCURS HERE - iNVALID POINTER: OBJECT(S) ERASED
    ProcessComponentCluster(cadSSet)
    'clear vars for next pass
    cadSSet.Delete()
    oComponent = New Component
    cadBRef = Nothing
    Next

    My next step is to try concantenating the counter value [lCntr] to the sset
    name and see if that resolves it. I thought I'd post this so anyone who
    might have run into can hopefully answer before I come back if this idea
    fails - can you tell I have a tight deadline :(

    Thanks,

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 5, 2004
    #1
  2. Odd.

    Have you breakpointed prior to the subr call to verify each object in the
    selection set? Object erased sounds like the type of error when an
    AcadEntity is deleted. Without the oComponent class or the InsertComponent
    procedure it is a bit tough. My bet is that:

    cadSSet.AddItems(cadBRefs)

    is somehow passing a bad object.


    (Don't you just hate deadlines?)

    --
    R. Robert Bell


    This is weird, but has anyone heard of or come across a limit on the number
    of times a selectionset can be re-used? I've got a monster app written in
    VB.NET using COM INTEROP that creates wiring schematics based on
    information retrieved from a C# webmethod - it automates the drawing task
    in AutoCAD 2005.

    The program pops an error every time on the 37th pass. I've checked all the
    obvious things I can think of - yes, the blocks are valid, are actually
    inserted and haven't been erased as is reported in the error. I've also
    reordered my JOB so the 37th pass contains different blocks just to make
    sure. At this moment in the program, about 350-600 blocks have been insert
    into the sset [2 to 60 per loop] during the 36 previous passes and the sset
    is deleted before it starts the next loop. I've even tried clearing the
    sset instead of deleting it. Since the program is massive, here's just the
    portion in question:

    For lCntr = 1 To Job.Count
    'grab Component from JOB
    oComponent = Job.Item(lCntr)
    'create an AutoCAD Selection Set
    cadSSet = m_cadDoc.SelectionSets.Add("iDrawing")
    'insert graphic and set reference to blockref
    cadBRef = InsertComponent(oComponent)
    'add blockref to selectionset
    cadBRefs(0) = cadBRef
    cadSSet.AddItems(cadBRefs)
    'loop to insert all subcomponents
    For lCntr2 = 1 To oComponent.Item.Count
    'insert graphic and set reference to blockref
    cadBRef = InsertComponent(oComponent.Item(lCntr2))
    'add blockref to selectionset
    cadBRefs(0) = cadBRef
    cadSSet.AddItems(cadBRefs)
    Next

    'move into position, populate attributes, etc.
    'PASSING SelSet BYREF so it records update insertion points
    'ERROR OCCURS HERE - iNVALID POINTER: OBJECT(S) ERASED
    ProcessComponentCluster(cadSSet)
    'clear vars for next pass
    cadSSet.Delete()
    oComponent = New Component
    cadBRef = Nothing
    Next

    My next step is to try concantenating the counter value [lCntr] to the sset
    name and see if that resolves it. I thought I'd post this so anyone who
    might have run into can hopefully answer before I come back if this idea
    fails - can you tell I have a tight deadline :(

    Thanks,

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    R. Robert Bell, Aug 5, 2004
    #2
  3. Yeah, I know that would be my reply =)
    Nope, each blockref passed to the cadBref array is valid as is the array
    itself.

    And I thought the C# webmethods intergrated was going to be the hard part -
    NOT AutoCAD!
    no reply - this is a monitored group

    --
    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 5, 2004
    #3
  4. Well, poo. (moderator or no!)

    I notice that there is no:
    cadSSet = Nothing

    I'm phishing now, with you, but could that help you?

    --
    R. Robert Bell


    Yeah, I know that would be my reply =)
    Nope, each blockref passed to the cadBref array is valid as is the array
    itself.

    And I thought the C# webmethods intergrated was going to be the hard part -
    NOT AutoCAD!
    no reply - this is a monitored group

    --
    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    R. Robert Bell, Aug 5, 2004
    #4
  5. I notice that there is no:
    I'm glad your phishing with me, Robert. I just sent youi an email. I don't
    know - will try it. While it should be there, I would've thought it'd stick
    it's ugly little head up before the 37th time thru?????

    Man, I never have simple problems :(

    Thanks a million Robert =)
     
    Mike Tuersley, Aug 5, 2004
    #5
  6. Hey, we're making headway! Adding the nothing increased my error to
    catastrophic - now that is messed up!!!

    "An unhandled exception of type
    'System.Runtime.InteropServices.COMException' occurred in
    SchematicGenerator.exe

    Additional information: Catastrophic failure"

    [gonna be a looonnnnggggggg night]

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 5, 2004
    #6
  7. Why this rather than reusing the same set each time?

    I noticed Robert's comment about cadBRef = Nothing.

    While I don't know if it's related to your problem this bit of code doesn't
    do what you might think. If you're handling a COM object, you need to
    explicitly release the reference with Marshal.ReleaseComObject as setting
    the reference to Nothing does not decrement the reference count. I've had
    that problem bite me more than once in COM interop projects. Police your COM
    references zealously.

    Also, where's the code for ProcessComponentCluster()?
     
    Frank Oquendo, Aug 5, 2004
    #7
  8. Have a look at my notes on the use of Nothing with respect to COM objects.
     
    Frank Oquendo, Aug 5, 2004
    #8
  9. Thank you Frank!
    duh! I missed that one. It *should* be before the loop
    Hmm never thought of that one - all of my cad objects are set to nothing
    come to think of it :-[
    I know, I know, I need smacked for not posting but its more complicated
    than I posted. ProcessComponentCluster is actually a function that branches
    out to 4 or 5 others, but it is the only one that does anythng to the
    selset. The drawing is organized into "columns" then cut into sheets via
    layouts. PCC calls functions that
    1. determine the overall bounding box of the selset
    2. determine the next column that has the vertical space free to place the
    selset in
    3. If no column exists with enough vertical space, a sub is called tto
    create another
    4. The selset is moved into position - the only time the selset is actually
    edited. It returns back fine -> X objects get sent, X objects return

    I'm gonna try your suggestions here and ten post ALL the processing code if
    it doesn't work! Thanks again Frank and Robert - you guys shave no idea how
    much I appreciate it.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 5, 2004
    #9
  10. Frank, what is a valid check to use on a com object prior to
    Marshal.ReleaseComObject? Should I use a If Not object = Nothing approach,
    or something different/better?

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 5, 2004
    #10
  11. In C#, I always use this:

    if (obj != null) {
    Marshal.ReleaseComObject(obj);
    obj = null;
    }

    Your code looks the same thing in VB but it's been a while so I'm not sure.
     
    Frank Oquendo, Aug 5, 2004
    #11
  12. Thanks! If it wasn't for the client requiring vb.net, I would rather have
    done c# - as we've discussed, I've made too many of my own problems because
    I automatically think in vb6 terms.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Aug 5, 2004
    #12
  13. Mike Tuersley

    Matthew Guest

    This is directly from the Acad help file.

    so AutoLISP is not permitted to have more than 128 open at one time. If this
    limit is reached, AutoCAD refuses to create any more selection sets and
    returns nil to all ssget calls. To close an unnecessary selection set
    variable, set it to nil.

    HTH
    Matthew
     
    Matthew, Aug 5, 2004
    #13
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.