.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Display Preview of DWG File in PictureBox

9 REPLIES 9
Reply
Message 1 of 10
vampirefromtheITcave
3068 Views, 9 Replies

Display Preview of DWG File in PictureBox

I'm trying to display a preview of an AutoCAD file in a PictureBox in VB.Net. I need to find a cheap way to do this and I have not been able to find an inexpensive solution. Is there a way to do this conversion in code?
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: vampirefromtheITcave

Am Mon, 20 Jul 2009 20:31:42 +0000 schrieb vampirefromtheITcave:

> From: vampirefromtheITcave <>
> Subject: Display Preview of DWG File in PictureBox
> Newsgroups: autodesk.autocad.customization.dotnet
> Path: discussion.autodesk.com
> Xref: discussion.autodesk.com autodesk.autocad.customization.dotnet:15614
> Content-Type: text/plain; charset="UTF-8"
> Content-Transfer-Encoding: quoted-printable
> Message-ID: <6221590@discussion.autodesk.com>
> References:
> Date: Mon, 20 Jul 2009 20:31:42 +0000
>
> I'm trying to display a preview of an AutoCAD file in a PictureBox in VB.Ne=
> t. I need to find a cheap way to do this and I have not been able to find =
> an inexpensive solution. Is there a way to do this conversion in code?

You can diplay the preview-bitmap stored in the dwg-file using
dwgthumbnail.ocx. Googling for it will show some download-locations.

HTH
Herbert
Message 3 of 10

I'm not sure if this has been tried, this will get the thumbnail as an Image object so it can be applied to a PictureBox:

Public Function abortFunc() As Boolean
End Function

Public Sub Asdkcmd1()

Dim myDwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim myDB As Database = myDwg.Database

Dim bm As System.Drawing.Bitmap = myDB.ThumbnailBitmap
Dim img As System.Drawing.Image = bm.GetThumbnailImage(bm.Width, bm.Height, New System.Drawing.Image.GetThumbnailImageAbort (AddressOf abortFunc), IntPtr.Zero)

Dim dlg As ThumbnailDialog = New ThumbnailDialog()
dlg.PictureBoxMain.Image = img
dlg.ShowDialog()

End Sub


Though If model space has a black background (Model - 2D Wireframe) the thumbnail ends up with a white background. Does the dwgthumbnail.ocx handle it the correct way? Having trouble finding that file.
Message 4 of 10
Anonymous
in reply to: vampirefromtheITcave

IMHO what has happened is that DWGThumbnail.OCX does not display preveiw of files saved with ACAD 2009 upwards.

I thought it was a pretty good of way of displaying previews without having to open the entire database and without having ACAD/RealDWG around.
Message 5 of 10

dwgthumbnail.ocx only allows me to use files up to the 2002 edition of AutoCAD. I need to be able to view files made by AutoCAD 2008. It would be nice if it were also compatible with 2010.
Message 6 of 10

Dim myDwg As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim myDB As Database = myDwg.Database

Dim bm As System.Drawing.Bitmap = myDB.ThumbnailBitmap
Dim img As System.Drawing.Image = bm.GetThumbnailImage(bm.Width, bm.Height, New System.Drawing.Image.GetThumbnailImageAbort (AddressOf abortFunc), IntPtr.Zero)

Dim dlg As ThumbnailDialog = New ThumbnailDialog()
dlg.PictureBoxMain.Image = img
dlg.ShowDialog()

For some reason vb.net does not recognize Document, Database, or ThumbnailDialog. Is there something I need to Import?
Message 7 of 10

Yeah, as long as you have your AutoCAD references added to your project, you just have to declare your imports at the top of your code file:

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.GraphicsSystem
etc...

Instead of having to type:
dim doc as Autodesk.AutoCAD.ApplicationServices.Document

you just just say:
dim doc as Document


The 'ThumbnailDialog' is just the name of a dialog that I created for this test project, it's just a System.Windows.Forms.Form. It can be any window that you have that has a 'PictureBox' in it:

So if you have a dialog that you are going to display named MyDialog:
Dim dlg as MyDialog = New MyDialog()
dlg.MyPictureBox.Image = img
dlg.ShowDialog()
Message 8 of 10
Anonymous
in reply to: vampirefromtheITcave

Am Tue, 21 Jul 2009 13:00:48 +0000 schrieb vampirefromtheITcave:

> dwgthumbnail.ocx only allows me to use files up to the 2002 edition of AutoCAD. I need to be able to view files made by AutoCAD 2008. It would be nice if it were also compatible with 2010.

I'm using 2.0.0.0 and it works with ACAD2010 files as well.
IIRC, there is an updated version available on adn.

Regards
Herbert
Message 9 of 10

I found a vb file called dwgtobmp.vb. I don't remember where I got it because I got it yesterday on one of the forums I was reading. Tested it today and it works well. Thanks for all the help everyone. If I can find the post again, I'll post a link here for anyone who needs it in the future. I'm not sure which versions it works with, but it works for 2008 and I don't foresee any issues with similar versions. I don't know a lot about AutoCAD though, so no guarantees.
Message 10 of 10

Maybe you can post that file?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost