• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    New Member
    Posts: 2
    Registered: ‎06-12-2005

    Save preview to file

    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.ThumbnailBitmap?

    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.Editor.WriteMessage("db loaded")
    If db.ThumbnailBitmap Is Nothing Then
    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("geen bitmap?")
    Else
    db.ThumbnailBitmap.Save("test.bmp")
    End If
    Catch ex As Exception
    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("test:" + ex.Message)
    Finally
    If Not bm Is Nothing Then bm.Dispose()
    End Try
    End Sub
    End Class
    Please use plain text.
    *Albert Szilvasy

    Re: Save preview to file

    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.ThumbnailBitmap?

    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.Editor.WriteMessage("db
    loaded")
    If db.ThumbnailBitmap Is Nothing Then
    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("geen
    bitmap?")
    Else
    db.ThumbnailBitmap.Save("test.bmp")
    End If
    Catch ex As Exception
    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("test:"
    + ex.Message)
    Finally
    If Not bm Is Nothing Then bm.Dispose()
    End Try
    End Sub
    End Class
    Please use plain text.
    New Member
    Posts: 2
    Registered: ‎06-12-2005

    Re: Save preview to file

    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.
    Please use plain text.
    *Tony Tanzillo

    Re: Save preview to file

    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):



    "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(filename));
    }
    }
    }

    //////////////////////////////////////////////////////////////////////////////

    --
    http://www.caddzone.com

    AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006
    http://www.acadxtabs.com
    Please use plain text.
    Valued Contributor
    Posts: 86
    Registered: ‎07-22-2006

    Re: Save preview to file

    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....
    Please use plain text.
    Distinguished Contributor
    Posts: 303
    Registered: ‎09-26-2004

    Re: Save preview to file

    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.DynamicLinker.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
    Please use plain text.
    *Tony Tanzillo

    Re: Save preview to file

    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.DynamicLinker.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
    Please use plain text.
    Valued Contributor
    Posts: 86
    Registered: ‎07-22-2006

    Re: Save preview to file

    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...
    Please use plain text.
    Valued Contributor
    Posts: 86
    Registered: ‎07-22-2006

    Re: Save preview to file

    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....
    Please use plain text.
    Distinguished Contributor
    Posts: 303
    Registered: ‎09-26-2004

    Re: Save preview to file

    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]
    Please use plain text.