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.
Re: show DWG file thumbnail image
Quote:
Originally Posted by
Coolmo
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'~
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. :p
Re: show DWG file thumbnail image
Quote:
Originally Posted by
Coolmo
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. :p
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'~
Re: show DWG file thumbnail image
Hi Coolmo
Check your post, please
~'J'~
Re: show DWG file thumbnail image
Quote:
Originally Posted by
Coolmo
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. :p
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. :)
Re: show DWG file thumbnail image
Quote:
Originally Posted by
mjohnston.26901
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
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
Re: show DWG file thumbnail image
Quote:
Originally Posted by
Kerry Brown
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.
Re: show DWG file thumbnail image
Quote:
Originally Posted by
Coolmo
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.