CreateAutoCADOffScreenDevice/GetSnapshot Changes in 2009 ???

CreateAutoCADOffScreenDevice/GetSnapshot Changes in 2009 ???

Anonymous
Not applicable
2,807 Views
20 Replies
Message 1 of 21

CreateAutoCADOffScreenDevice/GetSnapshot Changes in 2009 ???

Anonymous
Not applicable
I have a function (based largely on an ADN example 'Play2') that fails
in certain conditions on 2007/2008 but seems to work fine on 2009+. It
takes a block name and resolution parameters and returns a system bitmap.

The error is:
--------------------------------------------------
Runtime Error!
Program: C:\Program Files\AutoCAD 2008\acad.exe

R6025
- pure virtual function call
--------------------------------------------------

When you open a drawing and call this function (even numerous times)
everything works fine. However if you close and reopen the same drawing
(on 2007/2008) the error occurs immediately on the first call. Is there
possibly something being disposed that shouldn't be, etc. The fact that
it appears to work continuously on 2009+ leads me to suspect something
may have been fixed in AutoCAD?

The code attached is the exact function used, it should be usable and
standalone fairly well with one exception, substitute reasonable
coordinates for "AcdVue.ZoomExtents".

Thanks in advance,

Terry
0 Likes
2,808 Views
20 Replies
Replies (20)
Message 2 of 21

Anonymous
Not applicable
Since the text file attachment didn't work well, how about pasted inline
in the message.

Function BlockImage(ByVal BlkNam As String, ByVal UseWid As Integer,
ByVal UseHgt As Integer, Optional ByVal BufFac As Double = 1.1) As Bitmap
Dim RetBmp As New Bitmap(1, 1)
Dim BlkPts As List(Of PointXYZ) = BlockExtents(BlkNam)
Dim GraMan As GraphicsSystem.Manager =
Application.DocumentManager.MdiActiveDocument.GraphicsManager
Using DatBas As Database =
Application.DocumentManager.MdiActiveDocument.Database
Using TrnAct As Transaction =
DatBas.TransactionManager.StartTransaction
Using BlkTbl As BlockTable =
DatBas.BlockTableId.GetObject(OpenMode.ForRead)
Using AcdDev As GraphicsSystem.Device =
GraMan.CreateAutoCADOffScreenDevice()
Using BlkRec As BlockTableRecord =
TrnAct.GetObject(BlkTbl(BlkNam), OpenMode.ForRead)
Using AcdVue As New GraphicsSystem.View()
Using AcdMod As GraphicsSystem.Model =
GraMan.CreateAutoCADModel()
AcdDev.OnSize(New Size(UseWid + 1, UseHgt + 1))
AcdDev.Add(AcdVue)
AcdDev.Update()
AcdVue.Add(BlkRec, AcdMod)
AcdVue.ZoomExtents(PNT2P3D(BlkPts(0)),
PNT2P3D(BlkPts(1)))
AcdVue.Zoom(BufFac)
RetBmp = AcdVue.GetSnapshot(AcdVue.Viewport)
AcdVue.EraseAll()
AcdDev.Erase(AcdVue)
End Using
End Using
End Using
End Using
End Using
End Using
End Using
Return RetBmp
End Function
0 Likes
Message 3 of 21

Anonymous
Not applicable
I don't use/do VB.NET - wow a lot of usings calls 🙂

Can't tested here, but where is the commit for your transaction call? for
the model view - unless that is not available or required on vb.net.

Maybe.


"Terry W. Dotson" wrote in message
news:[email protected]...
Since the text file attachment didn't work well, how about pasted inline
in the message.

Function BlockImage(ByVal BlkNam As String, ByVal UseWid As Integer,
ByVal UseHgt As Integer, Optional ByVal BufFac As Double = 1.1) As Bitmap
Dim RetBmp As New Bitmap(1, 1)
Dim BlkPts As List(Of PointXYZ) = BlockExtents(BlkNam)
Dim GraMan As GraphicsSystem.Manager =
Application.DocumentManager.MdiActiveDocument.GraphicsManager
Using DatBas As Database =
Application.DocumentManager.MdiActiveDocument.Database
Using TrnAct As Transaction =
DatBas.TransactionManager.StartTransaction
Using BlkTbl As BlockTable =
DatBas.BlockTableId.GetObject(OpenMode.ForRead)
Using AcdDev As GraphicsSystem.Device =
GraMan.CreateAutoCADOffScreenDevice()
Using BlkRec As BlockTableRecord =
TrnAct.GetObject(BlkTbl(BlkNam), OpenMode.ForRead)
Using AcdVue As New GraphicsSystem.View()
Using AcdMod As GraphicsSystem.Model =
GraMan.CreateAutoCADModel()
AcdDev.OnSize(New Size(UseWid + 1, UseHgt + 1))
AcdDev.Add(AcdVue)
AcdDev.Update()
AcdVue.Add(BlkRec, AcdMod)
AcdVue.ZoomExtents(PNT2P3D(BlkPts(0)),
PNT2P3D(BlkPts(1)))
AcdVue.Zoom(BufFac)
RetBmp = AcdVue.GetSnapshot(AcdVue.Viewport)
AcdVue.EraseAll()
AcdDev.Erase(AcdVue)
End Using
End Using
End Using
End Using
End Using
End Using
End Using
Return RetBmp
End Function
0 Likes
Message 4 of 21

arcticad
Advisor
Advisor
Can you list which imports should be included?

Error 1 Too many arguments to 'Public Sub New()'.
Error 2 Type 'PointXYZ' is not defined.
Error 3 Type 'GraphicsSystem.Manager' is not defined.
Error 4 Type 'Database' is not defined.

Thanks
---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 5 of 21

Anonymous
Not applicable
{quote}

I don't use/do VB.NET - wow a lot of usings calls 🙂

{quote}

Yes, most of which are unnecessary, but what's really amusing
about that code is that all of those 'End Using' statements are
replaced by a single '}' (close curly brace) in C#:

using( IDisposable first = .... )
using( IDisposable second = ...)
using( IDisposable third = ... )
using( IDisposable fourth = ... )
using( IDisposable fifth = ... )
{
// blah blah blah...
}

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:[email protected]...
I don't use/do VB.NET - wow a lot of usings calls 🙂

Can't tested here, but where is the commit for your transaction call? for
the model view - unless that is not available or required on vb.net.

Maybe.


"Terry W. Dotson" wrote in message
news:[email protected]...
Since the text file attachment didn't work well, how about pasted inline
in the message.

Function BlockImage(ByVal BlkNam As String, ByVal UseWid As Integer,
ByVal UseHgt As Integer, Optional ByVal BufFac As Double = 1.1) As Bitmap
Dim RetBmp As New Bitmap(1, 1)
Dim BlkPts As List(Of PointXYZ) = BlockExtents(BlkNam)
Dim GraMan As GraphicsSystem.Manager =
Application.DocumentManager.MdiActiveDocument.GraphicsManager
Using DatBas As Database =
Application.DocumentManager.MdiActiveDocument.Database
Using TrnAct As Transaction =
DatBas.TransactionManager.StartTransaction
Using BlkTbl As BlockTable =
DatBas.BlockTableId.GetObject(OpenMode.ForRead)
Using AcdDev As GraphicsSystem.Device =
GraMan.CreateAutoCADOffScreenDevice()
Using BlkRec As BlockTableRecord =
TrnAct.GetObject(BlkTbl(BlkNam), OpenMode.ForRead)
Using AcdVue As New GraphicsSystem.View()
Using AcdMod As GraphicsSystem.Model =
GraMan.CreateAutoCADModel()
AcdDev.OnSize(New Size(UseWid + 1, UseHgt + 1))
AcdDev.Add(AcdVue)
AcdDev.Update()
AcdVue.Add(BlkRec, AcdMod)
AcdVue.ZoomExtents(PNT2P3D(BlkPts(0)),
PNT2P3D(BlkPts(1)))
AcdVue.Zoom(BufFac)
RetBmp = AcdVue.GetSnapshot(AcdVue.Viewport)
AcdVue.EraseAll()
AcdDev.Erase(AcdVue)
End Using
End Using
End Using
End Using
End Using
End Using
End Using
Return RetBmp
End Function
0 Likes
Message 6 of 21

Anonymous
Not applicable
LE wrote:

> Can't tested here, but where is the commit for your transaction call?
> for the model view - unless that is not available or required on
> vb.net.

Thanks for looking at it. There are no changes to the drawing/database
they we want to commit. Once the bitmap is obtained everything should
be discarded. A transaction abort could be added but is it really needed?

Terry
0 Likes
Message 7 of 21

Anonymous
Not applicable
arcticad wrote:

> Can you list which imports should be included?

This function is in a module that shares with others, so all these may
not be necessary for this function.

Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices

> Error 2 Type 'PointXYZ' is not defined.

As mentioned, substitute reasonable values for ZoomWindow. The
intention was to not bring additional functions and structures into the
picture, attempting to keep it lean as possible.

I know the instance of GraphicsManager should not be disposed, that's
why it's defined using DIM instead.

Terry
0 Likes
Message 8 of 21

Anonymous
Not applicable
Oh! I see those play2 and play3 samples ... with all the usings - calls ....

I remember doing an update for one of the Kean samples that generates
snapshots - but with C#, and I am very sure that I used commit... will look
around.



"Terry W. Dotson" wrote in message
news:[email protected]...
LE wrote:

> Can't tested here, but where is the commit for your transaction call?
> for the model view - unless that is not available or required on
> vb.net.

Thanks for looking at it. There are no changes to the drawing/database
they we want to commit. Once the bitmap is obtained everything should
be discarded. A transaction abort could be added but is it really needed?

Terry
0 Likes
Message 9 of 21

Anonymous
Not applicable
{quote}

There are no changes to the drawing/database
they we want to commit....

{quote}

You should pay more attention to these discussion groups
and other resources like Kean's blog.

You're not nearly as well-informed as you seem to think,
and hopefully, Luis or someone else will explain it to you.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
0 Likes
Message 10 of 21

Anonymous
Not applicable
Tony Tanzillo wrote:

> You should pay more attention to these discussion groups
> and other resources like Kean's blog.

Coincidentally, a C# unaltered compile of Kean's example ...

http://through-the-interface.typepad.com/through_the_interface/2007/04/taking_a_snapsh_1.html

... exhibits the exact same error as my function in the right sequence.

First, draw a line and save it as LINE.DWG for reuse, then ...

1) Start AutoCAD 2007/2008.
2) Netload OSS.DLL
3) Open LINE.DWG
4) Issue the OSS command, no problem yet.
5) Close the drawing, don't save changes.
6) Open the LINE.DWG again.
7) Issue the OSS command, crash.

The same process works fine in 2009 or higher.

Terry
0 Likes
Message 11 of 21

Anonymous
Not applicable
Tony Tanzillo wrote:

> You're not nearly as well-informed as you seem to think ...

Never claimed to be well-informed, but I can say "Getting a little
better every day!"

Terry
0 Likes
Message 12 of 21

Anonymous
Not applicable
I only have installed here A2009 and A2010 - I can install 2007 or 2008 but
don't needed for now - but I recall that the block view sample (if that was
inspired and taken from the arx sample back on those versions) had some bugs
that was causing exporadic crashes, sometimes while doing the panning or
when closing AutoCAD if I remember right - but as you said appears to work
on later acad versions.

Also, remember that Chad (objectdcl) used that particular sample and the
same problem, crashed AutoCAD - I think that it is resolved on the objectdcl
and the opendcl code....

I did an small command quickview arx/mfc using a little portions of that
sample, and got the problem resolved - sorry can post the code, it is for
the software company I work.

And by the way, I do not follow the samples provided on the ADN, just as
reference and normally I will try to avoid them, have learned much from
people like Tony, Owen, to mention just two that frequent here in the
customization ngs.

//--
"Terry W. Dotson" wrote in message
news:[email protected]...
Tony Tanzillo wrote:

> You're not nearly as well-informed as you seem to think ...

Never claimed to be well-informed, but I can say "Getting a little
better every day!"

Terry
0 Likes
Message 13 of 21

Anonymous
Not applicable
OK... was able to give it a try (using OSS code) and got your error on the
first post (on A2007 not on A2009 or A2010).

Will try to play a little bit and see what can I get.

//---
"Terry W. Dotson" wrote in message
news:[email protected]...
Tony Tanzillo wrote:

> You should pay more attention to these discussion groups
> and other resources like Kean's blog.

Coincidentally, a C# unaltered compile of Kean's example ...

http://through-the-interface.typepad.com/through_the_interface/2007/04/taking_a_snapsh_1.html

... exhibits the exact same error as my function in the right sequence.

First, draw a line and save it as LINE.DWG for reuse, then ...

1) Start AutoCAD 2007/2008.
2) Netload OSS.DLL
3) Open LINE.DWG
4) Issue the OSS command, no problem yet.
5) Close the drawing, don't save changes.
6) Open the LINE.DWG again.
7) Issue the OSS command, crash.

The same process works fine in 2009 or higher.

Terry
0 Likes
Message 14 of 21

Anonymous
Not applicable
Well, did several tests and indeed it will return the 'pure virtual function
call' message

On my first try outs was getting this on the JIT - by having a new class on
one of my existing projects:

--------------------------------------------------
************** Exception Text **************
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. --->
System.NullReferenceException: Object reference not set to an instance of
an object.
at Autodesk.AutoCAD.GraphicsSystem.Manager.CreateAutoCADOffScreenDevice()
at QPipe.OffscreenImageCreation.SnapshotToFile(String filename,
VisualStyleType vst) in
D:\Programming\ARX2007\MEP0000\QPipeVS9\OffscreenImageCreation.cs:line 87
at QPipe.OffscreenImageCreation.OffscreenSnapshot() in
D:\Programming\ARX2007\MEP0000\QPipeVS9\OffscreenImageCreation.cs:line 26
--- End of inner exception stack trace ---
--------------------------------------------------

Then, created a new SLN (VS2008) and use the 2007 references only and the
above jit error was gone, but still the same error you mentioned.

Time to report a bug to the adesk guys.

Maybe 🙂

//--
wrote in message news:[email protected]...
OK... was able to give it a try (using OSS code) and got your error on the
first post (on A2007 not on A2009 or A2010).

Will try to play a little bit and see what can I get.

//---
"Terry W. Dotson" wrote in message
news:[email protected]...
Tony Tanzillo wrote:

> You should pay more attention to these discussion groups
> and other resources like Kean's blog.

Coincidentally, a C# unaltered compile of Kean's example ...

http://through-the-interface.typepad.com/through_the_interface/2007/04/taking_a_snapsh_1.html

... exhibits the exact same error as my function in the right sequence.

First, draw a line and save it as LINE.DWG for reuse, then ...

1) Start AutoCAD 2007/2008.
2) Netload OSS.DLL
3) Open LINE.DWG
4) Issue the OSS command, no problem yet.
5) Close the drawing, don't save changes.
6) Open the LINE.DWG again.
7) Issue the OSS command, crash.

The same process works fine in 2009 or higher.

Terry
0 Likes
Message 15 of 21

Anonymous
Not applicable
LE wrote:

> Time to report a bug to the adesk guys.

Many thanks for your effort in confirming my suspicions. I doubt
anything will come of it since it's 2007/2008.

Thanks again!

Terry
0 Likes
Message 16 of 21

Anonymous
Not applicable
Well, I tried not much help at all, and you are welcome.

Maybe, your next resort is to make an arx app (maybe based on the blockview
sample) and export the functions via pinvoke, or something like that.

//--
Many thanks for your effort in confirming my suspicions. I doubt
anything will come of it since it's 2007/2008.

Thanks again!

Terry
0 Likes
Message 17 of 21

Anonymous
Not applicable
{quote}

Never claimed to be well-informed,

{quote}

You imply to be well-informed when someone who is much
more well-informed than yourself correctly points out an error
in your code (allowing a transaction to abort), and you just
blow them off, as if you already know better.

But, please don't let this keep you from undertaking further
excercises in self-humiliation, as I'm sure they'll instill great
confidence in those whom you are trying to peddling the
result of your learning excises to.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"Terry W. Dotson" wrote in message
news:[email protected]...
Tony Tanzillo wrote:

> You're not nearly as well-informed as you seem to think ...

Never claimed to be well-informed, but I can say "Getting a little
better every day!"

Terry
0 Likes
Message 18 of 21

Anonymous
Not applicable
I gave it another fresh try, earlier today to the code:
OffscreenImageCreation.cs

And found the problem and fixed it... it is the View view = new View();
call - what's it is interesting is why on later version the original code
works as-is, and why the first use of the command OSS works, did not went in
deep into that.

The solution that works here it is:

1. - You can get rid off basically all the using's calls - in my case I
removed all of them
2. - Then start a transaction to wrap all the calls after this line:
int vpn = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

3. Make use of one Drawable object - in my case I used the BTR - model
space - the same one it is use on the sample.

4. Instead of the use of View view = new View();

Replace it with:

View view = gsm.CreateAutoCADView(btr); // or your own Drawable - temp.

5. Then do the commit at the end of the using:

tr.Commit();

And should work - I don't get any crash anymore - on all my tests here - did
not tested under a later AutoCAD version but I think it will work too.

See if helps.

//--
"Tony Tanzillo"
{quote}

Never claimed to be well-informed,

{quote}

You imply to be well-informed when someone who is much
more well-informed than yourself correctly points out an error
in your code (allowing a transaction to abort), and you just
blow them off, as if you already know better.

But, please don't let this keep you from undertaking further
excercises in self-humiliation, as I'm sure they'll instill great
confidence in those whom you are trying to peddling the
result of your learning excises to.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"Terry W. Dotson" wrote in message
news:[email protected]...
Tony Tanzillo wrote:

> You're not nearly as well-informed as you seem to think ...

Never claimed to be well-informed, but I can say "Getting a little
better every day!"

Terry
0 Likes
Message 19 of 21

Anonymous
Not applicable
Hmm... spoke to soon, it does not crash while having AutoCAD open, only when
closing... my guess that one of the using that I removed might be needed,
but will left that for you or other to give it a try 🙂

Was interesting if you tell me 🙂
Luis.

wrote in message news:[email protected]...
I gave it another fresh try, earlier today to the code:
OffscreenImageCreation.cs

And found the problem and fixed it... it is the View view = new View();
call - what's it is interesting is why on later version the original code
works as-is, and why the first use of the command OSS works, did not went in
deep into that.

The solution that works here it is:

1. - You can get rid off basically all the using's calls - in my case I
removed all of them
2. - Then start a transaction to wrap all the calls after this line:
int vpn = System.Convert.ToInt32(Application.GetSystemVariable("CVPORT"));

3. Make use of one Drawable object - in my case I used the BTR - model
space - the same one it is use on the sample.

4. Instead of the use of View view = new View();

Replace it with:

View view = gsm.CreateAutoCADView(btr); // or your own Drawable - temp.

5. Then do the commit at the end of the using:

tr.Commit();

And should work - I don't get any crash anymore - on all my tests here - did
not tested under a later AutoCAD version but I think it will work too.

See if helps.

//--
"Tony Tanzillo"
{quote}

Never claimed to be well-informed,

{quote}

You imply to be well-informed when someone who is much
more well-informed than yourself correctly points out an error
in your code (allowing a transaction to abort), and you just
blow them off, as if you already know better.

But, please don't let this keep you from undertaking further
excercises in self-humiliation, as I'm sure they'll instill great
confidence in those whom you are trying to peddling the
result of your learning excises to.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

"Terry W. Dotson" wrote in message
news:[email protected]...
Tony Tanzillo wrote:

> You're not nearly as well-informed as you seem to think ...

Never claimed to be well-informed, but I can say "Getting a little
better every day!"

Terry
0 Likes
Message 20 of 21

Anonymous
Not applicable
LE wrote:

> Hmm... spoke to soon, it does not crash while having AutoCAD open,
> only when closing... my guess that one of the using that I removed
> might be needed, but will left that for you or other to give it a try
>
With those changes, in my function it does not crash immediately after
opening the drawing but does after it is called a few times or at best
crashes on closing.

I 'think' I've tried all the combinations of Using -vs- Dim and can't
seem to stabilize it, will keep trying.

Thanks for the effort and constructive response.

Terry
0 Likes