Activate a document during a close event

Discussion in 'AutoCAD' started by Barry Ralphs, Mar 16, 2005.

  1. Barry Ralphs

    Barry Ralphs Guest

    I have this VBA code that re-loads an xref after it's been closed. It
    reloads the xref just fine, but when I hit save in the originl DWG I get the
    error:

    Command: _qsave
    Document "X:\2003dwgs\03151\struct\151S1-01.dwg" has a command in progress.
    Hit enter to cancel or [Retry]: *Cancel*

    It seams to be an API bug in Acad2002, since it works fine in Acad2004+
    Is there any other way around this or to fix this?



    Private Sub AcadDocument_BeginClose()
    Dim objDoc As AcadDocument
    Dim bFlag As Boolean

    For Each objDoc In ThisDrawing.Application.Documents
    Dim objBlk As AcadBlock

    For Each objBlk In objDoc.Blocks
    If objBlk.IsXRef = True Then

    If UCase(Mid(ThisDrawing.Name, 1, Len(ThisDrawing.Name) - 4)) =
    UCase(objBlk.Name) Then
    objDoc.Activate 'This is the line that is causing the error
    objBlk.Reload
    Exit For
    End If
    End If
    Next objBlk
    Next objDoc
    End Sub
     
    Barry Ralphs, Mar 16, 2005
    #1
  2. hi barry

    i have not tried your code, but what i think is that during the close-event you can't change the active doc.

    therefor some questions, because my feeling is that there is something wrong:

    if you try to update the doc's which use the "closing-dwg" as xref then you try to program what autocad2005 has as default

    if you run your code, you don't know at this point (...BeginClose) what the user answers to the question Save/Not Save during close.
    when the user answers "Don't Save" then your update is ok (but in that case you don't have to wait for ...BeginClose), when the user answers "Yes-
    Save" then your update-routine makes the update before the save was finished.

    - alfred -
     
    Alfred NESWADBA, Mar 17, 2005
    #2
  3. Barry Ralphs

    Barry Ralphs Guest

    Thx Alfred for your replay. Unfortunately I didn't write the code, so I'm a
    little confused.

    The code does work. The xref does get reloaded with the saved changes and
    you're probably right, it probably gets reloaded even if it didn't get
    saved. The thing I don't understand is why I get the error in the original
    dwg (not the xref) in Acad2002 & I don't in Acad2005. I'm just hoping to
    find a way to get it to work in Acad2002 until we can upgrade.





    close-event you can't change the active doc.
    you try to program what autocad2005 has as default
    the user answers to the question Save/Not Save during close.
    case you don't have to wait for ...BeginClose), when the user answers "Yes-
     
    Barry Ralphs, Mar 18, 2005
    #3
  4. I wouldn't waste your time - shelf it till you get 2005. In the timeframe
    between the two, a lot of things changed and its possible that something
    the program is using was not available in 2002.

    -- Mike
    ___________________________
    Mike Tuersley
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Mar 18, 2005
    #4
  5. hi,

    then i have to rethink all of my code, because in my head the event "...BeginClose"
    always was before the question for save yes/no. well you tested it.

    it's hard for me now to test with 2002 because i don't have it on the current machine,
    just one more question to your code-line "objDoc.Activate": have you tried your app
    without that line? if the following line works, then "objDoc.Activate" does nothing
    then flicker your screen for every doc that has the xref in it, but the
    function of reload will also work, if the doc is not in foreground.

    - alfred -




     
    Alfred NESWADBA, Mar 18, 2005
    #5
  6. Barry Ralphs

    Barry Ralphs Guest

    Yes I've tried it without the "objDoc.Activate" & it doesn't work. ;-(


     
    Barry Ralphs, Mar 18, 2005
    #6
  7. so as not having 2002 at the moment, i hope you get help from anyone else,
    i for myself do not understand, why document.activate is needed.

    sorry for that, alfred
     
    Alfred NESWADBA, Mar 18, 2005
    #7
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.