See the top rated post in this thread. Click here

Page 1 of 4 1234 LastLast
Results 1 to 10 of 32

Thread: show DWG file thumbnail image

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

    Default show DWG file thumbnail image

    Can someone please show or tell me how to show a drawing file thumbnail image in a picture box using VB.NET? I've been searching the internet for about 6 MONTHS now on how to do this and every snippet of code and "how to" results in errors. I do not want to use Drawingthumbnail.OCX. I have a listbox filled with drawing names that returns the full path of the file I want to show when clicked. It cannot be this hard?! Can it? If someone has this code in one of their programs can you please post it? I'm going crazy here! Thanks in advance.

    I'm running AutoCAD 2007 BTW.

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Quote Originally Posted by Coolmo View Post
    Can someone please show or tell me how to show a drawing file thumbnail image in a picture box using VB.NET? I've been searching the internet for about 6 MONTHS now on how to do this and every snippet of code and "how to" results in errors. I do not want to use Drawingthumbnail.OCX. I have a listbox filled with drawing names that returns the full path of the file I want to show when clicked. It cannot be this hard?! Can it? If someone has this code in one of their programs can you please post it? I'm going crazy here! Thanks in advance.

    I'm running AutoCAD 2007 BTW.
    Hi Coolmo
    Try this code snippet (don't remebere where I'd stoled this one)
    Code:
      public partial class Form1 : Form
        {
            string folder = String.Empty;
            string dwgname = String.Empty;
            string blockname = String.Empty;
            public Form1()
            {
                InitializeComponent();
            }
            [DllImport("acdb17.dll", EntryPoint = "?acdbDisplayPreviewFromDwg@@YA_NPB_WPAXPBK@Z",
      CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
            extern static private bool DisplayPreviewFromDwg(string filename, IntPtr hwnd, ref int color);
     
            private void Form1_Load(object sender, EventArgs e)
            {
                // First create a FolderBrowserDialog object
                FolderBrowserDialog FolderBrowserDialog1 = new FolderBrowserDialog();
                // Then use the following code to create the Dialog window
                // Change the SelectedPath property to the default location
                using (FolderBrowserDialog1)
                {
                    // Desktop is the root folder in the dialog.
                    FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.DesktopDirectory;
                    // Select the C:\Custom directory on entry.
                    FolderBrowserDialog1.SelectedPath = @"C:\Custom";//<-- initial folder
                    // Prompt the user with a custom message.
                    FolderBrowserDialog1.Description = "* Select A Block Library Folder *";
                    if (FolderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        // Display the selected folder if the user clicked on the OK button.
                        folder = FolderBrowserDialog1.SelectedPath;
                        if (!folder.EndsWith("\\", StringComparison.CurrentCultureIgnoreCase))
                        {
                            folder = folder + "\\";
                        }
                        //MessageBox.Show(folder);//debug only
                    }
                }
                string[] fileNames = Directory.GetFiles(folder, "*.dwg");
                foreach (string fileName in fileNames)
                {
                    if (fileName.EndsWith(".dwg", StringComparison.CurrentCultureIgnoreCase))
                    {
                        FileInfo fi = new FileInfo(fileName);
                        dwgname = fi.Name;
                        if (dwgname.Contains(".dwg"))
                        {
                            blockname = dwgname.Substring(0, dwgname.LastIndexOf(".dwg")); 
                            this.lstDrawings.Items.Add(blockname.ToUpper());//listBox control
                        }
                    }
                }
                this.Text = blockname;
                this.Activate();
            }
     
            private void btnExit_Click(object sender, EventArgs e)
            {
                this.Close();
            }
            private void lstDrawings_Click(object sender, EventArgs e)
            {
                blockname = this.lstDrawings.SelectedItem.ToString();
                string dwgname = folder + blockname + ".dwg";
                if (File.Exists(dwgname))
                {
                    this.dwgPickBox.Refresh();//PictureBox control
                    int intColor = System.Drawing.ColorTranslator.ToWin32(Color.White);
                    bool res = DisplayPreviewFromDwg(dwgname, this.dwgPickBox.Handle, ref intColor);
                }
                else
                {
                    MessageBox.Show(string.Format("Can't access to file: \n {0}", dwgname));
                }
            }
    }
    Working good on my end (A2009)

    ~'J'~

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

    Default Re: show DWG file thumbnail image

    Thank you, thank you, thank you so much for some code on this. I'm working with VB.Net instead of... C#? I think that's C. Can the same code and methods be used in VB? The DisplayPreviewFromDwg seems a little TOO easy. It appears (with my best guess at following this language) that you simply need a drawing name and the path where it exists to display it in a picturebox. Is there anything "weird' I need to load or import first for all this to work? The whole "DLLimport..." at the beginning seems to be key here. Is that a download or something readily available from my 2007 "out 'o da box" resources. I'll try it tonight. thanks again for the code.

    P.S. If ya happen to have this in VB.NET, I'll gladly name my first born after you.

  4. #4
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Quote Originally Posted by Coolmo View Post
    Thank you, thank you, thank you so much for some code on this. I'm working with VB.Net instead of... C#? I think that's C. Can the same code and methods be used in VB? The DisplayPreviewFromDwg seems a little TOO easy. It appears (with my best guess at following this language) that you simply need a drawing name and the path where it exists to display it in a picturebox. Is there anything "weird' I need to load or import first for all this to work? The whole "DLLimport..." at the beginning seems to be key here. Is that a download or something readily available from my 2007 "out 'o da box" resources. I'll try it tonight. thanks again for the code.

    P.S. If ya happen to have this in VB.NET, I'll gladly name my first born after you.
    Dear Coolmo,
    Unfortunatelly I can't rich at AutoCAD/VStudio on today
    I'll translate this code on VB.NET tomorrow
    Wait, please, no worries
    Have a nice all

    PS
    Thanks, you make me fun
    Just for your interest: my name is Oleg
    which becomes to viking's name Olaf

    ~'J'~
    Last edited by fixo; 2010-07-25 at 08:35 PM. Reason: spell check

  5. #5
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,269
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    Hi Coolmo
    Check your post, please

    ~'J'~

  6. #6
    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
    Thank you, thank you, thank you so much for some code on this. I'm working with VB.Net instead of... C#? I think that's C. Can the same code and methods be used in VB? The DisplayPreviewFromDwg seems a little TOO easy. It appears (with my best guess at following this language) that you simply need a drawing name and the path where it exists to display it in a picturebox. Is there anything "weird' I need to load or import first for all this to work? The whole "DLLimport..." at the beginning seems to be key here. Is that a download or something readily available from my 2007 "out 'o da box" resources. I'll try it tonight. thanks again for the code.

    P.S. If ya happen to have this in VB.NET, I'll gladly name my first born after you.
    I found this to be just what I needed. (and it's VB.NET)
    http://www.theswamp.org/index.php?topic=30985.0

    Please do not have any children on my account.

  7. #7
    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
    I found this to be just what I needed. (and it's VB.NET)
    http://www.theswamp.org/index.php?topic=30985.0

    Please do not have any children on my account.
    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

  8. #8
    Active Member
    Join Date
    2006-08
    Location
    Brisbane : GMT+10
    Posts
    87
    Login to Give a bone
    0

    Default Re: show DWG file thumbnail image

    I know this may sound like a really wild suggestion, but
    why don't you ask the original poster at theSwamp ?
    and perhaps thank him for posting the code at the same time.

    Yours courteously,
    etc

  9. #9
    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
    I know this may sound like a really wild suggestion, but
    why don't you ask the original poster at theSwamp ?
    and perhaps thank him for posting the code at the same time.

    Yours courteously,
    etc
    Boo...

    Not to step on toes here but I'm kinda a one forum guy and I asked my original question here. The answers (at this forum) might actually help others (at this forum) instead of some sort of endless link after link into another forum... and then into another. I REALLY DO appreciate the link to the swamp's forum solution and the original poster at that forum, but the personal experience and knowledge of mjohnston.26901 might take me a bit further into my question and solution with his/her personal take on the code and not to mention in the wake of all this... stuff... might help others... here, at this forum, the forum I signed up for and goto the most.

  10. #10
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,396
    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
    Its not in the code you downloaded, but it it is in Keith's post.
    C:> ED WORKING....

Page 1 of 4 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
  •