See the top rated post in this thread. Click here

Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 32

Thread: show DWG file thumbnail image

  1. #11
    Member
    Join Date
    2015-11
    Posts
    9
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Quote Originally Posted by Coolmo View Post
    The code seems simple enough but the "acThumbnailReader" is not declared in the code given and I have no idea what to declare it "As". Help? Thanks for the code link BTW
    Coolmo,
    acThumbnailReader is the class contained in the download. I'm not a VB.NET guy but in C# I just call the methods of acThumnailReader. The methods are static so the class doesn't have to be instantiated (declared).

    On the subject of multiple forums etc. - Aren't you glad I don't feel the same way? Either I wouldn't have found Keith's awesome solution or I wouldn't have posted an answer to your question. I had been away from this forum for a while but I'm glad I came back. There is a nice group here. I also frequent the Swamp and the Adesk forums and try to participate in all of them.
    Last edited by mjohnston.26901; 2010-08-18 at 06:14 PM.

  2. #12
    All AUGI, all the time
    Join Date
    2003-10
    Posts
    706
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Quote Originally Posted by mjohnston.26901 View Post
    Coolmo,
    acThumbnailReader is the class contained in the download. I'm not a VB.NET guy but in C# I just call the methods of acThumnailReader. The methods are static so the class doesn't have to be instantiated (declared).

    On the subject of multiple forums etc. - Aren't you glad I don't feel the same way? Either I wouldn't have found Keith's awesome solution or I wouldn't have posted an answer to your question. I had been away from this forum for a while but I'm glad I came back. There is a nice group here. I also frequent the Swamp and the Adesk forums and try to participate in all of them.

    Thanks for the info. I'll dig further into your link. Ed also mentioned that the answer was there. Thank you.

    Again, I'm not trying to make people mad or NOT give credit where credit is due but the previous post I quoted and responded to just seemed a little sarcastic like I was some ungrateful... whatever... that didn't appreciate the link or the original poster of the link. Not true... but maybe I took it wrong. I apologize if I did. I still think the answer, when found, should be posted into this forum for the Augi masses as well. I'm also a member of the Autodesk forum but I mostly search and answer here.

  3. #13
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Is the Attached picture what you are looking for
    Attached Images Attached Images

  4. #14
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    1

    Default Re: show DWG file thumbnail image

    Here is link to the VB.Net solution
    http://www.theswamp.org/index.php?topic=34923.0

  5. #15
    All AUGI, all the time
    Join Date
    2003-10
    Posts
    706
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Quote Originally Posted by jeffhornsby View Post
    Here is link to the VB.Net solution
    http://www.theswamp.org/index.php?topic=34923.0
    Thanks for the link and code. Apparently I've touched a nerve with these guys/gals per their posts and replys. I will appoligize to Kerry... Sorry for any confusion or bad vibes Kerry, but I also tried to find the code which everyone was talking about and the only thing I found missing was a download that 'The Swamp" said I was not allowed to download (acThumnailViewer.zip or something) so I couldn't get it to work. With that... another brick wall. I assume that if I signed up for their forum I could download it but quotes like (and joyful replys to)...

    "Another Useless Group of Individuals" refering to the AUGI forum kinda turns me away, not to mention the code that was held hostage with the terms of an apology. I can't believe what this simple quest for code has turned into. Thanks for smacking down those who wanna learn.
    Last edited by RobertB; 2010-09-21 at 09:29 PM. Reason: fixed quote

  6. #16
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Hey man I did not mean anything by it. I think AUGI is a great place and it would be great if everyone learning AutoCAD's API were all at the same place, but each fourm has a certian feel or vibe to it due to the member's and administraitor's. And people perfer certain one's

    I know how annoying it is to find information on the API, a little snag that stops a project, or finding what to P/Invoke etc....... And most of the time it is from something simple but you can not find any documentation on it.

    From your post It easy to tell that you eager and motivated to learn, and it was the wrong to go about it and i apoligize, but it was basiclly to tell you that if you can't get a answer here come ask it at the swamp, and there are plenty of people who would be glad to help out. Same goes for people at the Swamp I am sure when they can not find a answer there they come here because each forum is full of smart guys and gals.

    Again I apologize and I will make sure you are able to get a image on a PictureBox because that is what is about helping each other learn.

    Also I have messed around with Standard details library that fills a Listview on a tool pallete. Basiclly it will fill the Listview(if you are not fimiliar with a listview a generic way of explaining it would be the right side window of window explorer) and names the images by drawing name(minus the extension) and groups them under a title named by each Sub-Directory Name. You chose different views list,details etc....
    When you double click it on a pic it will bring in all entities from that drawing in etc... with different settings to choose from. If this is something that would help.

    I am not sure what type of applacation this is for but I would be glad to help out if need it because I will learn things from you and it is always better to get other's input.

    I am not sure if you have VS2010 but I will load it up here. It would be Simple to change to VS2008

    This would not be considered anything worth using for any buisness application due to no error handleing or that way it get's the files.....etc it was just to quickly fill a picture box with an image.


    Anyways here is code behind the form. It is very basic. 95% of the code is handling the right click menu. And the bottom half is thumbnail reader class that fills another picture box.
    You can use the thumbnail reader class outside of AutoCAD to get the Thumbnail. AutoCAD does not have to be installed to get Bitmap.


    There are some other tricks to grabbing them so you can go another route
    This will only work if you have the same name and settings on a form

    Please reply back with anything you need help with
    Code:
    Imports System.IO
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.ApplicationServices.Application
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Runtime
    Imports System.Drawing
    Public Class FillPictureBoxForm
    
        Private Sub FillPictureBoxForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            FillCombo()
        End Sub
    
        'Fills the Combo Box
        Private Sub FillCombo()
            ''Because this method is called for differnt reasons
            ''and if you change 
            cboFileNmae.Items.Clear()
    
            Dim rootFolder As String = My.MySettings.Default.RootFolder
            If Directory.Exists(rootFolder) Then
                If My.MySettings.Default.SearchSub Then
                    For Each dwgFile As String In Directory.GetFiles(rootFolder, "*.dwg", SearchOption.AllDirectories)
                        cboFileNmae.Items.Add(dwgFile)
                    Next
                Else
                    For Each dwgFile As String In Directory.GetFiles(rootFolder, "*.dwg")
                        cboFileNmae.Items.Add(dwgFile)
                    Next
                End If
    
            End If
        End Sub
     
        'When the comboBox Changes It Changes the File Preview
        Private Sub cboFileNmae_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFileNmae.SelectedIndexChanged
    
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''This gets the filename from the combobox 
            ''Which is a terrible way to do it there are better ways
            Dim fName As String = cboFileNmae.Text
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''This is the code that fills the pictureBox
            Dim db As Database = New Database(False, False)
            db.ReadDwgFile(fName, FileOpenMode.OpenForReadAndReadShare, False, "")
            Dim tmbNail As Bitmap = db.ThumbnailBitmap
            picBoxThumbnail.Image = tmbNail
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            ''''' This is a call to the thumbnail reader you would need this one if you did not have autocad runnig
            picBoxJGR.Image = ThumbnailReader.GetThumbnail(fName)
            ' ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''       
        End Sub
    
    
    #Region "ContextMenu"  ''Code for Right Click Menu  
        '' Handle the the True and False Check Status whenever it is Opening
        Private Sub ContexMenu_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContexMenu.Opening
            TrueToolStripMenuItem.Checked = My.MySettings.Default.SearchSub
            FalseToolStripMenuItem.Checked = Not TrueToolStripMenuItem.Checked
    
        End Sub
        ''Code for Selecting Root Folder to Look in Dwgs
        Private Sub SelectFolderToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectFolderToolStripMenuItem.Click
            '' Save the settings this way so they persist and will save what
            ''folder you chose to be used next time you run autocad
            If FBD.ShowDialog = Windows.Forms.DialogResult.OK Then
                My.MySettings.Default.RootFolder = FBD.SelectedPath
                My.MySettings.Default.Save()
                FillCombo()
            End If
        End Sub
        ''If you set to true then will search all sub Directories of Root Folder
        Private Sub TrueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrueToolStripMenuItem.Click
            My.MySettings.Default.SearchSub = True
            My.MySettings.Default.Save()
            TrueToolStripMenuItem.Checked = True
            FalseToolStripMenuItem.Checked = False
            FillCombo()
        End Sub
        ''If you set to false then will not search all sub Directories of Root Folder
        Private Sub FalseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FalseToolStripMenuItem.Click
            My.MySettings.Default.SearchSub = False
            My.MySettings.Default.Save()
            TrueToolStripMenuItem.Checked = False
            FalseToolStripMenuItem.Checked = True
            FillCombo()
        End Sub
    #End Region
    
        '''''''''''''''''''''''''''''''''''''''''''''''''''
    End Class

  7. #17
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    It would not all fit so here is the thumbnail reader, there is no error handling
    and this one sometimes will throw a eBadheader error
    And here is the solution
    Again there can be many improvments made so please reply with any questions are problems

    When you run it right click the form and select the folder to load the files from
    The way it is implemented I would not choose a folder with over a 100 drawings or set search sub-folders to true with alot of nested folders

    also after netload you can just type showf then press tab until the commnad comes up


    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''';'' Thumbnail reader class
    Friend NotInheritable Class ThumbnailReader
    ''''''''''
        <System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)> _
        Private Structure tagBITMAPFILEHEADER
    
            Public bfType As UShort
    
            Public bfSize As UInteger
    
            Public bfReserved1 As UShort
    
            Public bfReserved2 As UShort
    
            Public bfOffBits As UInteger
        End Structure
    
        Friend Shared Function GetThumbnail(ByVal filename As String) As Bitmap
    
            Using fs As FileStream = File.OpenRead(filename)
                Using br As BinaryReader = New BinaryReader(fs)
                    Dim datLoc As Integer
                    Dim bytCnt As Byte
    
                    ' TODO
                    ' Modificar para leer directamente el centinela
                    fs.Seek(13, SeekOrigin.Begin)
                    datLoc = br.ReadInt32()
                    datLoc += 20
                    fs.Seek(datLoc, SeekOrigin.Begin)
                    bytCnt = br.ReadByte()
    
                    If bytCnt <= 1 Then
                        Return Nothing
                    End If
    
                    Dim imgHeaderStart As Int32
                    Dim imgHeaderSize As Int32
                    Dim imgCode As Byte
    
                    For i As Short = 1 To bytCnt
    
                        imgCode = br.ReadByte()
                        imgHeaderStart = br.ReadInt32()
                        imgHeaderSize = br.ReadInt32()
    
                        If imgCode = 2 Then
                            fs.Seek(imgHeaderStart, SeekOrigin.Begin)
    
                            '-----------------------------------------------------
                            ' TODO
                            ' Deberia comprobar si asi es mas rapido, o leer cada bloque uno a uno
                            Dim bmpHeader(40) As Byte
                            bmpHeader = br.ReadBytes(40)
    
                            Dim biBitCount As UShort = BitConverter.ToUInt16(New Byte() {bmpHeader(14), bmpHeader(15)}, 0)
                            Dim biSizeImage As UInteger = BitConverter.ToUInt16(New Byte() {bmpHeader(20), bmpHeader(21), bmpHeader(22), bmpHeader(23)}, 0)
                            '-----------------------------------------------------
    
                            fs.Seek(imgHeaderStart, SeekOrigin.Begin)
    
                            Dim bytBMPBuff(imgHeaderSize) As Byte
                            bytBMPBuff = br.ReadBytes(imgHeaderSize)
    
                            Dim clrTableSize As UInteger = CUInt(If(biBitCount < 9, 4 * (2 ^ biBitCount), 0))
                            Dim bfHeader As tagBITMAPFILEHEADER
    
                            With bfHeader
                                .bfType = &H4D42
                                .bfSize = CUInt(54) + clrTableSize + biSizeImage
                                .bfOffBits = CUInt(54) + clrTableSize
                            End With
    
                            Using ms As New MemoryStream
    
                                Using bw As BinaryWriter = New BinaryWriter(ms)
                                    bw.Write(bfHeader.bfType)
                                    bw.Write(bfHeader.bfSize)
                                    bw.Write(bfHeader.bfReserved1)
                                    bw.Write(bfHeader.bfReserved2)
                                    bw.Write(bfHeader.bfOffBits)
                                    bw.Write(bytBMPBuff)
    
                                    Dim bm As Bitmap = New Bitmap(ms)
                                    Return bm
                                End Using
    
                            End Using
    
    
    
                        ElseIf imgCode = 3 Then
    
                            Return Nothing
                        End If
    
                    Next
    
                End Using
            End Using
    
            Return Nothing
        End Function
    
    End Class
    Attached Files Attached Files
    Last edited by Jeff H; 2010-09-21 at 04:34 AM.

  8. #18
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    I just noticed your post said listbox for some reason I thought it said comboBox can change it to a list box if need be

  9. #19
    All AUGI, all the time
    Join Date
    2003-10
    Posts
    706
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Quote Originally Posted by jeffhornsby View Post
    I just noticed your post said listbox for some reason I thought it said comboBox can change it to a list box if need be
    I just wanted to populate a listbox with DWG files from a certain folder, which I have the code for working seamlessly, but then I simply wanted to be able to click a filename within the listbox and have its thumbnail image appear in a small picturebox above the list. I'm use to passing the filename to the old school OCX drawing preview and was hoping VB.NET was just as easy. Thanks for all the help on this. I'll start diving into your code soon. Hopefully no hard feelings on ANY of this. Thanks again.

  10. #20
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    None at all this one is alot smaller and more what you said you wanted
    Loaded the project and picture
    I hope this helps if not please reply back

    Also 2011 broke CapturePreviewImage but it is supposed to be fixed in the Update
    I have MEP installed and they have not released the update's for the vertical autocad's so I do not know if it works yet .

    Click the folder then select a folder than select a file

    Here is the code

    command
    Code:
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.ApplicationServices.Application
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Runtime
    
    Public Class Class1
        ''This is to command to Show the Form
        <CommandMethod("lbForm", CommandFlags.Modal)>
        Public Sub lbForm()
            Dim frm As New Form1
            Application.ShowModalDialog(frm)
        End Sub
    End Class


    form
    Code:
    Imports System.IO
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.ApplicationServices.Application
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Runtime
    Imports System.Drawing
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If Fbd.ShowDialog = Windows.Forms.DialogResult.OK Then
                lstbxFiles.Items.Clear()
                For Each fName In Directory.GetFiles(Fbd.SelectedPath, "*.dwg")
                    Me.lstbxFiles.Items.Add(fName)
                Next
            End If
        End Sub
    
        Private Sub lstbxFiles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstbxFiles.SelectedIndexChanged
            Dim db As Database = New Database(False, False)
            Dim fname As String = lstbxFiles.SelectedItem.ToString()
            db.ReadDwgFile(fname, FileOpenMode.OpenForReadAndReadShare, False, "")
            Dim tmbNail As Bitmap = db.ThumbnailBitmap
            picBox.Image = tmbNail
        End Sub
    End Class
    Attached Images Attached Images
    Attached Files Attached Files

Page 2 of 4 FirstFirst 1234 LastLast

Similar Threads

  1. API type question: Replace Revit Thumbnail Image
    By Marek Brandstatter in forum Revit Architecture - General
    Replies: 10
    Last Post: 2018-02-09, 06:36 PM
  2. Drawing File Thumbnail Preview
    By Coolmo in forum Dot Net API
    Replies: 3
    Last Post: 2010-03-19, 09:55 AM
  3. Updating Preview thumbnail image in sheet sets
    By mf in forum AutoCAD Sheet Set Manager
    Replies: 3
    Last Post: 2006-09-13, 04:54 PM
  4. AutoCAD 2005 TIFF Image files - Image file not valid
    By richard_hamilton in forum AutoCAD General
    Replies: 3
    Last Post: 2004-09-30, 11:39 PM
  5. multiple image show
    By nigel.chesworth in forum AutoCAD General
    Replies: 2
    Last Post: 2004-09-14, 11:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •