.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
644 Views, 19 Replies
06-12-2005 12:34 PM
Hi all,
I try to save the thumbnail to a file, but it seems ThumbnailBitmap is alway's nothing. Does anyone know how to use this Autodesk.AutoCAD.DatabaseServices.Database.Thumbna ilBitmap?
thanks,
Evert
----
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports System.Collections
Imports System.Text
Imports System.Drawing
Public Class PreviewBitMap
Public Sub test()
Dim bm As Bitmap
Dim db As Database
Try
'Get the current database
db = HostApplicationServices.WorkingDatabase
Application.DocumentManager.MdiActiveDocument.Edit or.WriteMessage("db loaded")
If db.ThumbnailBitmap Is Nothing Then
Application.DocumentManager.MdiActiveDocument.Edit or.WriteMessage("geen bitmap?")
Else
db.ThumbnailBitmap.Save("test.bmp")
End If
Catch ex As Exception
Application.DocumentManager.MdiActiveDocument.Edit or.WriteMessage("test:" + ex.Message)
Finally
If Not bm Is Nothing Then bm.Dispose()
End Try
End Sub
End Class
I try to save the thumbnail to a file, but it seems ThumbnailBitmap is alway's nothing. Does anyone know how to use this Autodesk.AutoCAD.DatabaseServices.Database.Thumbna
thanks,
Evert
----
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports System.Collections
Imports System.Text
Imports System.Drawing
Public Class PreviewBitMap
Public Sub test()
Dim bm As Bitmap
Dim db As Database
Try
'Get the current database
db = HostApplicationServices.WorkingDatabase
Application.DocumentManager.MdiActiveDocument.Edit
If db.ThumbnailBitmap Is Nothing Then
Application.DocumentManager.MdiActiveDocument.Edit
Else
db.ThumbnailBitmap.Save("test.bmp")
End If
Catch ex As Exception
Application.DocumentManager.MdiActiveDocument.Edit
Finally
If Not bm Is Nothing Then bm.Dispose()
End Try
End Sub
End Class
*Albert Szilvasy
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
06-12-2005 08:49 PM in reply to:
EvertM
You can't set a thumbnail currently. I consider this a bug so I'll make sure
we have defect logged.
albert
wrote in message news:4872660@discussion.autodesk.com...
Hi all,
I try to save the thumbnail to a file, but it seems ThumbnailBitmap is
alway's nothing. Does anyone know how to use this
Autodesk.AutoCAD.DatabaseServices.Database.Thumbna ilBitmap?
thanks,
Evert
----
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports System.Collections
Imports System.Text
Imports System.Drawing
Public Class PreviewBitMap
Public Sub test()
Dim bm As Bitmap
Dim db As Database
Try
'Get the current database
db = HostApplicationServices.WorkingDatabase
Application.DocumentManager.MdiActiveDocument.Edit or.WriteMessage("db
loaded")
If db.ThumbnailBitmap Is Nothing Then
Application.DocumentManager.MdiActiveDocument.Edit or.WriteMessage("geen
bitmap?")
Else
db.ThumbnailBitmap.Save("test.bmp")
End If
Catch ex As Exception
Application.DocumentManager.MdiActiveDocument.Edit or.WriteMessage("test:"
+ ex.Message)
Finally
If Not bm Is Nothing Then bm.Dispose()
End Try
End Sub
End Class
we have defect logged.
albert
Hi all,
I try to save the thumbnail to a file, but it seems ThumbnailBitmap is
alway's nothing. Does anyone know how to use this
Autodesk.AutoCAD.DatabaseServices.Database.Thumbna
thanks,
Evert
----
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports System.Collections
Imports System.Text
Imports System.Drawing
Public Class PreviewBitMap
Public Sub test()
Dim bm As Bitmap
Dim db As Database
Try
'Get the current database
db = HostApplicationServices.WorkingDatabase
Application.DocumentManager.MdiActiveDocument.Edit
loaded")
If db.ThumbnailBitmap Is Nothing Then
Application.DocumentManager.MdiActiveDocument.Edit
bitmap?")
Else
db.ThumbnailBitmap.Save("test.bmp")
End If
Catch ex As Exception
Application.DocumentManager.MdiActiveDocument.Edit
+ ex.Message)
Finally
If Not bm Is Nothing Then bm.Dispose()
End Try
End Sub
End Class
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
06-22-2005 08:07 AM in reply to:
EvertM
I reported this, but the thumbnail attribute has the status 'Not Implemented' (yet). It would be nice if autocad would throw an 'Not Implemented' error instead of just returning Nothing.
*Tony Tanzillo
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
06-22-2005 09:44 AM in reply to:
EvertM
"Albert Szilvasy" wrote
>> You can't set a thumbnail currently. I consider this
>> a bug so I'll make sure we have defect logged.
If the objective is getting the bitmap, as opposed to
setting it, the problem is most likely this (from the
docs for AcDbDatabase::thumbnailBitmap):
I haven't tried this, but it should work (please let me know
if it doesn't).
/////////////////// ThumbnailExtractor.cs ///////////////////////
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
namespace acdbUtils
{
public class ThumbnailExtractor
{
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetPreviewBitmap@@YAPAUtagBITMAPINFO@@PBD@Z" )]
extern static private IntPtr acdbGetPreviewBitmap(string filename);
static Bitmap GetBitmapFromDwg(string filename)
{
return Marshaler.BitmapInfoToBitmap(acdbGetPreviewBitmap( filename));
}
}
}
////////////////////////////////////////////////// ////////////////////////////
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com
>> You can't set a thumbnail currently. I consider this
>> a bug so I'll make sure we have defect logged.
If the objective is getting the bitmap, as opposed to
setting it, the problem is most likely this (from the
docs for AcDbDatabase::thumbnailBitmap):
"Note These APIs are meant primarily for ObjectDBX developers.
Preview thumbnail behavior reflect what the host application must
do to generate a preview.
For ObjectARX developers AutoCAD is taking care of all preview
thumbnail generation. ObjectARX users should leave these APIs
alone, and allow AutoCAD behaviors to prevail.
Most of the time, the AcDbDatabase::thumbnailBitmap() method
will return nothing, since the bitmap is not read into memory by
AcDbDatabase::readDwgFile(). To retreive the thumbnail from the
DWG file, (as opposed to directly from the db) the same existing
ObjectARX standalone functions are preferred. (for example
acdbDisplayPreviewFromDwg())".
I haven't tried this, but it should work (please let me know
if it doesn't).
/////////////////// ThumbnailExtractor.cs ///////////////////////
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
namespace acdbUtils
{
public class ThumbnailExtractor
{
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetPreviewBitmap@@YAPAUtagBITMAPINFO@@PBD@Z"
extern static private IntPtr acdbGetPreviewBitmap(string filename);
static Bitmap GetBitmapFromDwg(string filename)
{
return Marshaler.BitmapInfoToBitmap(acdbGetPreviewBitmap(
}
}
}
//////////////////////////////////////////////////
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
http://www.acadxtabs.com
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-26-2006 11:11 PM in reply to:
EvertM
Sir ,
As you told i tried this code but it didn't work
-----------
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
namespace acdbUtils
{
public class ThumbnailExtractor
{
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetPreviewBitmap@@YAPAUtagBITMAPINFO@@PBD@Z" )]
extern static private IntPtr acdbGetPreviewBitmap(string filename);
static Bitmap GetBitmapFromDwg(string filename)
{
return Marshaler.BitmapInfoToBitmap(acdbGetPreviewBitmap( filename));
}
}
-----------------------
Thanks....
As you told i tried this code but it didn't work
-----------
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
namespace acdbUtils
{
public class ThumbnailExtractor
{
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acdb16.dll", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acdbGetPreviewBitmap@@YAPAUtagBITMAPINFO@@PBD@Z"
extern static private IntPtr acdbGetPreviewBitmap(string filename);
static Bitmap GetBitmapFromDwg(string filename)
{
return Marshaler.BitmapInfoToBitmap(acdbGetPreviewBitmap(
}
}
-----------------------
Thanks....
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-31-2006 07:17 AM in reply to:
EvertM
[code]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("dwgpreview.arx", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi ,
EntryPoint = "SaveDWGPreview")]
extern static private int SaveDWGPreview(string dwgfilename, string bmpfilename);
[CommandMethod("SavePreview")]
public void SavePreview()
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLink er.LoadModule("DWGPreview.arx",false,false);
SaveDWGPreview(db.Filename,"C:\\dwgpreview.bmp");
}
[/code]
dwgpreview.arx for AutoCAD 2004...2006 is attached Message was edited by: Alexander Rivilis
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("dwgpreview.arx", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi ,
EntryPoint = "SaveDWGPreview")]
extern static private int SaveDWGPreview(string dwgfilename, string bmpfilename);
[CommandMethod("SavePreview")]
public void SavePreview()
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLink
SaveDWGPreview(db.Filename,"C:\\dwgpreview.bmp");
}
[/code]
dwgpreview.arx for AutoCAD 2004...2006 is attached Message was edited by: Alexander Rivilis
*Tony Tanzillo
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
08-31-2006 09:10 AM in reply to:
EvertM
For AutoCAD 2007, this should do it:
/// Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
// This form requires a PictureBox named 'pictureBox1':
namespace ThumbnailSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// R17 ONLY
[DllImport( "acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedGenerateThumbnailBitmap@@YAPAUtagABITMAPINFO @@XZ" )]
private static extern IntPtr acedGenerateThumbnailBitmap();
private void ThumbView_Load( object sender, EventArgs e )
{
IntPtr bmi = acedGenerateThumbnailBitmap();
if( bmi != IntPtr.Zero )
{
Bitmap bm = Marshaler.BitmapInfoToBitmap( bmi );
pictureBox1.Image = (System.Drawing.Image) bm.Clone();
bm.Dispose();
}
}
[CommandMethod( "THUMBVIEW" )]
public static void doit()
{
using( Form1 form = new Form1() )
AcadApp.ShowModalDialog( form );
}
}
}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
wrote in message news:5313888@discussion.autodesk.com...
[code]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("dwgpreview.arx", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi ,
EntryPoint = "SaveDWGPreview")]
extern static private int SaveDWGPreview(string dwgfilename, string bmpfilename);
[CommandMethod("SavePreview")]
public void SavePreview()
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLink er.Load
Module("DWGPreview.arx",false,false);
SaveDWGPreview(db.Filename,"C:\\dwgpreview.bmp");
}
[/code]
dwgpreview.arx for AutoCAD 2004...2006 is attached
Message was edited by: Alexander Rivilis
/// Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
// This form requires a PictureBox named 'pictureBox1':
namespace ThumbnailSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// R17 ONLY
[DllImport( "acad.exe", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "?acedGenerateThumbnailBitmap@@YAPAUtagABITMAPINFO
private static extern IntPtr acedGenerateThumbnailBitmap();
private void ThumbView_Load( object sender, EventArgs e )
{
IntPtr bmi = acedGenerateThumbnailBitmap();
if( bmi != IntPtr.Zero )
{
Bitmap bm = Marshaler.BitmapInfoToBitmap( bmi );
pictureBox1.Image = (System.Drawing.Image) bm.Clone();
bm.Dispose();
}
}
[CommandMethod( "THUMBVIEW" )]
public static void doit()
{
using( Form1 form = new Form1() )
AcadApp.ShowModalDialog( form );
}
}
}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
[code]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("dwgpreview.arx", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi ,
EntryPoint = "SaveDWGPreview")]
extern static private int SaveDWGPreview(string dwgfilename, string bmpfilename);
[CommandMethod("SavePreview")]
public void SavePreview()
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLink
Module("DWGPreview.arx",false,false);
SaveDWGPreview(db.Filename,"C:\\dwgpreview.bmp");
}
[/code]
dwgpreview.arx for AutoCAD 2004...2006 is attached
Message was edited by: Alexander Rivilis
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-03-2006 12:33 AM in reply to:
EvertM
Sir,
Your code is working great. But i want to know does it not works for Autocad 2007 3D Drawings template(acad3D.dwt type files). If i want to save all types of autocad files's thumbanil then how can i achive this.
Thanks...
Your code is working great. But i want to know does it not works for Autocad 2007 3D Drawings template(acad3D.dwt type files). If i want to save all types of autocad files's thumbanil then how can i achive this.
Thanks...
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-03-2006 08:29 PM in reply to:
EvertM
Hi rivilis,
I want to know if you have got dwgpreview.arx for Autocad 2007. IF not then how can i do it in 2007. Tony's code is working but not for 3D drawings.
Thanks....
I want to know if you have got dwgpreview.arx for Autocad 2007. IF not then how can i do it in 2007. Tony's code is working but not for 3D drawings.
Thanks....
Re: Save preview to file
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
09-04-2006 02:35 AM in reply to:
EvertM
Try it:
[code]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("dwgpreview.arx", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "SaveDWGPreview")]
extern static private int SaveDWGPreview(string dwgfilename, string bmpfilename);
[/code]
[code]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("dwgpreview.arx", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode,
EntryPoint = "SaveDWGPreview")]
extern static private int SaveDWGPreview(string dwgfilename, string bmpfilename);
[/code]


