BeginSave

BeginSave

Anonymous
Not applicable
219 Views
3 Replies
Message 1 of 4

BeginSave

Anonymous
Not applicable
I'm receiving some fatal errors that seem to be connected to some code written inside the BeginSave event. The odd thing about it is it happens AFTER the first save when the user saves again.

I wrote the code in an attempt to solve a raster design problem we're having.

Pretty much it is doing this:
1. Compare ThisDrawing.Name w/ ByVal FileName
2. Create a selection set of Raster Images
3. If SS.Count <= 1 then
4. If in Paperspace switch to Modelspace
5. Save*
6. Switch back to Paperspace and complete the initial Save

* Does this pose a problem? Using the Save method from within the BeginSave Event?

The error:
"FATAL ERROR: Unhandled Access Violation Reading 0x0000 Exception at 7c1ba6f4h"
0 Likes
220 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
I think you might have a recursion problem because the BeginSave event is
called anytime that the drawing is to be saved regardless of user or program
initiated. So I think that your save in step 5 might retrigger the event.
You could add a Static variable to check to see if the routine is running
and if it is then skip the save.

--
Phil Custer II, P.E.
Custer Services, Inc.
custer@landfillgas.com

wrote in message news:5088284@discussion.autodesk.com...
I'm receiving some fatal errors that seem to be connected to some code
written inside the BeginSave event. The odd thing about it is it happens
AFTER the first save when the user saves again.

I wrote the code in an attempt to solve a raster design problem we're
having.

Pretty much it is doing this:
1. Compare ThisDrawing.Name w/ ByVal FileName
2. Create a selection set of Raster Images
3. If SS.Count <= 1 then
4. If in Paperspace switch to Modelspace
5. Save*
6. Switch back to Paperspace and complete the initial Save

* Does this pose a problem? Using the Save method from within the BeginSave
Event?

The error:
"FATAL ERROR: Unhandled Access Violation Reading 0x0000 Exception at
7c1ba6f4h"
0 Likes
Message 3 of 4

Anonymous
Not applicable
I thought I could get around that by using this tidbit:

If ThisDrawing.ActiveSpace = acPaperSpace Then
ThisDrawing.ActiveSpace = acModelSpace
ThisDrawing.Save
ThisDrawing.ActiveSpace = acPaperSpace
End If

...but i'm liking your idea better. Trouble is, I'm not too familiar, actually, not familiar at all, with static vars other than they retain values.

Would I be a pain if I asked, how does one go about defining a static variable?
0 Likes
Message 4 of 4

Anonymous
Not applicable
I tested this in AutoCAD V2006 as part of the drawing object.
You can remove the debug.print after you test this.
Note that Static variables are local to the procedure but maintain their
value across calls to the procedure.
The printout from the immediate window of this looks like this:

BeginSave Call Count: 1 Allready Called => False
BeginSave Call Count: 2 Allready Called => True

[code]
Private Sub AcadDocument_BeginSave(ByVal FileName As String)
Static InSaveSub As Boolean
Static CallCount As Integer
CallCount = CallCount + 1
Debug.Print "BeginSave Call Count: ", CallCount, " Allready Called => ",
InSaveSub
If Not InSaveSub Then
InSaveSub = True
If ThisDrawing.ActiveSpace = acPaperSpace Then
ThisDrawing.ActiveSpace = acModelSpace
ThisDrawing.Save
ThisDrawing.ActiveSpace = acPaperSpace
End If
End If
InSaveSub = False
CallCount = CallCount - 1
End Sub
[/code]

--
Phil Custer II, P.E.
Custer Services, Inc.
custer@landfillgas.com

wrote in message news:5088355@discussion.autodesk.com...
I thought I could get around that by using this tidbit:

If ThisDrawing.ActiveSpace = acPaperSpace Then
ThisDrawing.ActiveSpace = acModelSpace
ThisDrawing.Save
ThisDrawing.ActiveSpace = acPaperSpace
End If

...but i'm liking your idea better. Trouble is, I'm not too familiar,
actually, not familiar at all, with static vars other than they retain
values.

Would I be a pain if I asked, how does one go about defining a static
variable?
0 Likes