See the top rated post in this thread. Click here

Page 4 of 4 FirstFirst 1234
Results 31 to 32 of 32

Thread: show DWG file thumbnail image

  1. #31
    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 Kerry Brown View Post
    The code you posted ... was that in-line or a public function ?

    I have a Public Sub that takes the DWG filename selected from a listbox and then runs the bit by bit code on the filename selected to extract the bitmap image (thumbnail) and before it passes the image to the picturebox I stuck this code in to "process" the bitmap image and invert the colors.

    Technically I want to change all the pixels that are white to black and all that are black, change to white but I figured that's easy enough once I query every pixel to list its color. if I can get the image to invert the colors through this code I should be able to do that.
    Last edited by Coolmo; 2010-09-22 at 03:52 PM.

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

    Default Re: show DWG file thumbnail image

    I thought I would throw this in for you when you double click the the picture it will prompt you to click for a insertion point, and insert the drawing in the picture as a block. I thought I saw a post by you that you wanted to mimic the insert command.

    There are three constructors for the Database.Insert

    Here is what the docs say about the constructor I am using
    This function mimics the AutoCAD INSERT command. First a new block table record is created in the database executing this function. This new block table record is given the name pointed to by blockName. Then, all the Model Space entities in the database pointed to by dataBase are copied into the new block table record.

    The preserveSourceDatabase argument determines whether the source database dataBase is left intact. The default value of the argument is true. In that case, objects from the source database are copied to the destination database, and the source database is not changed. If the caller passes false for this argument, objects from the source database could be physically moved into the destination database. The latter runs faster, but it leaves the source database dependent on the destination database. The caller should make sure that the source database is deleted either immediately, or at least before the destination database is deleted.

    Returns the object ID for the new block table record created by this function.
    Here is the added code to last post I did

    Code:
    Imports System.IO
    Imports Autodesk.AutoCAD.ApplicationServices
    Imports Autodesk.AutoCAD.ApplicationServices.Application
    Imports Autodesk.AutoCAD.DatabaseServices
    Imports Autodesk.AutoCAD.Runtime
    Imports System.Drawing
    Imports Autodesk.AutoCAD.EditorInput
    Imports Autodesk.AutoCAD.Geometry
    
    Public Class Form1
        Private Shared folderName As String = ""
        Private Shared filename As String = ""
        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
                folderName = Fbd.SelectedPath
                lstbxFiles.Items.Clear()
                For Each fName In Directory.GetFiles(folderName, "*.dwg")
                    Me.lstbxFiles.Items.Add(Path.GetFileNameWithoutExtension(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)
            filename = lstbxFiles.SelectedItem.ToString()
            db.ReadDwgFile(folderName & "\" & filename & ".dwg", FileOpenMode.OpenForReadAndReadShare, False, "")
    
            Dim tmbNail As Bitmap = db.ThumbnailBitmap
            picBox.Image = tmbNail
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    
        End Sub
     
        Private Sub picBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picBox.Click
            Dim fname As String = folderName & "\" & filename & ".dwg"
            Dim ObjId As ObjectId
            Dim db As Database = HostApplicationServices.WorkingDatabase()
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Using trans As Transaction = db.TransactionManager.StartTransaction
                Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
                Dim btr As BlockTableRecord = bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
                Using dbInsert As New Database(False, True)
                    dbInsert.ReadDwgFile(fname, IO.FileShare.Read, True, "")
                    ObjId = db.Insert(Path.GetFileNameWithoutExtension(fname), dbInsert, True)
                End Using
                Dim ppo As New PromptPointOptions("Insertion Point")
                Dim ppr As PromptPointResult
                ppr = ed.GetPoint(ppo)
                If ppr.Status <> PromptStatus.OK Then
                    ed.WriteMessage(vbCrLf & "You decided to QUIT!")
                    Exit Sub
                End If
                Dim insertPt As Point3d = ppr.Value
                Dim bref As New BlockReference(insertPt, ObjId)
                btr.AppendEntity(bref)
                trans.AddNewlyCreatedDBObject(bref, True)
                trans.Commit()
            End Using
    
        End Sub
      End Class
    Last edited by Jeff H; 2010-09-27 at 05:17 AM.

Page 4 of 4 FirstFirst 1234

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
  •