Activate a document during a close event
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Activate a document during a close event

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
Barry Ralphs
Guest





Posted: Thu Mar 17, 2005 3:40 am    Post subject: Activate a document during a close event Reply with quote

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

Back to top
Alfred NESWADBA
Guest





Posted: Fri Mar 18, 2005 2:41 am    Post subject: Re: Activate a document during a close event Reply with quote

In article <4238b5f0$1_1@newsprd01>, "Barry Ralphs" <barryATtippingmarDOTcom> says...
Quote:
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



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 -
Back to top
Barry Ralphs
Guest





Posted: Fri Mar 18, 2005 6:19 am    Post subject: Re: Activate a document during a close event Reply with quote

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.





"Alfred NESWADBA" <alfred.neswadba@hollaus.nomail.at> wrote in message
news:MPG.1ca417ffe480e003989697@discussion.autodesk.com...
Quote:
In article <4238b5f0$1_1@newsprd01>, "Barry Ralphs"
barryATtippingmarDOTcom> says...
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



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 -


Back to top
Mike Tuersley
Guest





Posted: Fri Mar 18, 2005 9:58 am    Post subject: Re: Activate a document during a close event Reply with quote

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...
Back to top
Alfred NESWADBA
Guest





Posted: Fri Mar 18, 2005 4:29 pm    Post subject: Re: Activate a document during a close event Reply with quote

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 -




In article <423a2cb6$1_2@newsprd01>, "Barry Ralphs" <barryATtippingmarDOTcom> says...
Quote:
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.





"Alfred NESWADBA" <alfred.neswadba@hollaus.nomail.at> wrote in message
news:MPG.1ca417ffe480e003989697@discussion.autodesk.com...
In article <4238b5f0$1_1@newsprd01>, "Barry Ralphs"
barryATtippingmarDOTcom> says...
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
Back to top
Barry Ralphs
Guest





Posted: Fri Mar 18, 2005 10:58 pm    Post subject: Re: Activate a document during a close event Reply with quote

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


"Alfred NESWADBA" <alfred.neswadba@hollaus.nomail.at> wrote in message
news:MPG.1ca4d9e66ae3bf2989698@discussion.autodesk.com...
Quote:
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 -




In article <423a2cb6$1_2@newsprd01>, "Barry Ralphs"
barryATtippingmarDOTcom> says...
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.





"Alfred NESWADBA" <alfred.neswadba@hollaus.nomail.at> wrote in message
news:MPG.1ca417ffe480e003989697@discussion.autodesk.com...
In article <4238b5f0$1_1@newsprd01>, "Barry Ralphs"
barryATtippingmarDOTcom> says...
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
Back to top
Alfred NESWADBA
Guest





Posted: Fri Mar 18, 2005 11:12 pm    Post subject: Re: Activate a document during a close event Reply with quote

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


In article <423b16dc$1_3@newsprd01>, "Barry Ralphs" <barryATtippingmarDOTcom> says...
Quote:
Yes I've tried it without the "objDoc.Activate" & it doesn't work. ;-(


"Alfred NESWADBA" <alfred.neswadba@hollaus.nomail.at> wrote in message
news:MPG.1ca4d9e66ae3bf2989698@discussion.autodesk.com...
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 -




In article <423a2cb6$1_2@newsprd01>, "Barry Ralphs"
barryATtippingmarDOTcom> says...
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.





"Alfred NESWADBA" <alfred.neswadba@hollaus.nomail.at> wrote in message
news:MPG.1ca417ffe480e003989697@discussion.autodesk.com...
In article <4238b5f0$1_1@newsprd01>, "Barry Ralphs"
barryATtippingmarDOTcom> says...
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
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB