I'm trying to convert a VBA application to .Net.
First things first: AutoDesk's .Net implementation sucks and the lack of cohesive documentation is pathetically shameful. Why should I have to search far and wide to try and get enough information to make this crap work? This situation is unconscionable. And yet here we are, years after release, and they still don't have their crap together on this. Seems like everything about AutoCAD is steadily going downhill. It used to be a professional quality package. Now, it is rife with problems that the company ignores and it has absolutely the WORST documentation of the API of any professional product I have ever seen.
My latest go-around with this travesty:
I need to load a PictureBox with an image from a file at runtime.
PictureBox1.Image = Image.FromFile("Image.bmp")
-> Results in the error: 'FromFile' is not a member of 'Autodesk.AutoCAD.DatabaseServices.Image'.
Huh? This is how Visual Studio tells me to load an image. I guess AutoDesk thought better of it.
PictureBox1.Image.FromFile("Image.bmp")
-> Results in the error: 'Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.'
These examples were both taken directly from Visual Studio's help. Does anybody know of an approach that works?
Solved! Go to Solution.
Solved by chiefbraincloud. Go to Solution.
Solved by Hallex. Go to Solution.
Have you tryed:
Imports System.Drawing
--------------------------
PictureBox1.Image = System.Drawing.Image.FromFile("Image.bmp")?
~'J'~
I thought I had tried that using IntelliSense to guide me, but it didn't work that way. Just putting it in manually seemed to do the trick. Thanks!
Try the attached class. Works fine on 2007 and 2008 on 32 and 64 bits machines.
I use it to provide previews of DWGs of dynamic blocks and other blocks that are not currently opened.
I use it this way combined with a list box with the full names of the dwgs
string myDWGPath = Path.Combine(FileServer, listBoxProfiles.Text);
Bitmap dwgThumb = ThumbnailReader.GetThumbnail(myDWGPath,false);
pictureBox.Image = dwgThumb;
if (dwgThumb != null)
{
// whatever you like
}
else
{
// whatever exception handling you like
}
It's obvious that you have Imported Autodesk.AutoCAD.DatabaseServices, and have not imported System.Drawing. If you do Import System.Drawing, then the Image reference will be ambiguous, existing in both System.Drawing, and Autodesk.AutoCAD.DatabaseServices.
You just need to explicitly specify the System.Drawing.Image
PictureBox1.Image = System.Drawing.Image.FromFile("Image.bmp")
Thanks, ognyandim, but you seem to have replied to the wrong topic...
That explains my problem.
Thanks, guys.
You can get a thumb from you file either with the same class. It doesnt matter if it is DWG or JPG, or BMP or whatever. You can strech yout thumb to whatever size you want after you get it.