Author Topic: how to get preview dwg without autocad ?  (Read 48347 times)

0 Members and 1 Guest are viewing this topic.

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: how to get preview dwg without autocad ?
« Reply #30 on: June 08, 2014, 07:01:35 PM »
far as I know that's based on the settings in the autocad instance which created it

Squazz

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #31 on: November 16, 2015, 07:44:37 AM »
vs2010EX acad2012.

I have been converting this code to C# but evidently there are methods in vb.net that are not in C#.
The FileStream (fs) does not contain "CopyTo" in my intellisense. Any way to work around that?
Code: [Select]
if (imageCode == 6)       //PNG Preview (2013 file format);
           {
              fs.Seek(imageHeaderStart, SeekOrigin.Begin);         

              using (MemoryStream ms = new MemoryStream())
                {
                 
                 fs.CopyTo(ms, imageHeaderStart);
                 Image img = Image.FromStream(ms);
                 return new Bitmap(img);
                }   //end using
           } //end if

This is not an emergency I am just doing this for my own education.
I can't test it right now anyways but they are threatening me with an upgrade to 2013 Acad.
The entire file is attached.

Trying out the code from BillZndl, I simply cannot get it to work. I'm constantly getting a "image fromstream parameter is not valid" error, no matter if I'm using dwg files from 2010, 2011, 2013 or 2015. I have attached the files I'm trying this with for reference.

BillZndl

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #32 on: November 16, 2015, 08:16:32 AM »
Wish I could help.
I'm still on 2012 Acad which I know will not work with this code.

Squazz

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #33 on: November 16, 2015, 08:34:09 AM »
Wish I could help.
I'm still on 2012 Acad which I know will not work with this code.
Which code are you on then? The one from Keith?

BillZndl

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #34 on: November 16, 2015, 01:10:46 PM »
I think I changed to the one attached because of some background color issues with one I was using.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: how to get preview dwg without autocad ?
« Reply #35 on: November 16, 2015, 01:37:19 PM »
The one I provided early on in this thread does not handle the png images embedded in the drawing very well.

I've just revisited this project because I needed to update a software package. I've implemented several of the changes in my new thumbnail reader class and it works great for drawings up to AutoCAD 2015.

I am not where I can upload the file, but if I get a chance I'll do it later today.

Keep in mind that if there is not a drawing preview saved in the DWG file, then no preview will be available.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Squazz

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #36 on: November 17, 2015, 02:54:12 AM »
I think I changed to the one attached because of some background color issues with one I was using.

That's also the one I'm having the best results with :)

The one I provided early on in this thread does not handle the png images embedded in the drawing very well.

I've just revisited this project because I needed to update a software package. I've implemented several of the changes in my new thumbnail reader class and it works great for drawings up to AutoCAD 2015.

I am not where I can upload the file, but if I get a chance I'll do it later today.

Keep in mind that if there is not a drawing preview saved in the DWG file, then no preview will be available.
I will be looking forward to that, would be AWESOME :) Thanks in advance

BillZndl

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #37 on: November 19, 2015, 12:29:58 PM »
Keith,
just thought I'd throw this out there.

The acThumbnailReader would fail if the dwg was open by another user/computer.
I looked at the code and it looked like it was opening the file as read only.
Code - C#: [Select]
  1. fs = File.OpenRead(strFile);
I got around this by checking to see if the file was locked before I tried to use it.
Code - C#: [Select]
  1.  WhoHasInfo info = AcadApp.GetWhoHasInfo(FlNam);
  2.  
  3.                         if (!info.IsFileLocked)
  4.                         {

Just thought it was funny that it would not be able to open the dwg in read mode.





The one I provided early on in this thread does not handle the png images embedded in the drawing very well.

I've just revisited this project because I needed to update a software package. I've implemented several of the changes in my new thumbnail reader class and it works great for drawings up to AutoCAD 2015.

I am not where I can upload the file, but if I get a chance I'll do it later today.

Keep in mind that if there is not a drawing preview saved in the DWG file, then no preview will be available.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: how to get preview dwg without autocad ?
« Reply #38 on: November 20, 2015, 01:58:33 AM »
Interesting .. considering I tested it with several open drawings and there was no issue. If it becomes an issue, I'd suggest checking the lock status prior to calling the GetBitmap method.

Anyway, I've attached the dll that you can include in your projects. It reads all thumbnails from R14 to R2015 and should read through R2017 because there are no scheduled DWG format changes in the works.

This particular build has one public method GetBitmap and it accepts two parameters, filename and boolean retainBackColor.

A little more research into the preview section in the DWG file indicates that there is the possibility that the image format can be BMP, WMF or PNG (imagetype will be 2, 3, 6 respectively).

Also, the images can have pretty much any valid palette type and it makes a huge difference when swapping the background colors. For now, I've only coded the 8bit palette color swap. If you set retainBackColor to "false" the background will be solid black, otherwise it will be whatever color AutoCAD decides it needs to be.

A bitmap image is returned to the calling function so it can be saved from there or manipulated additionally.

I have found one minor bug in the image extraction. If the AutoCAD drawing window has an aspect ratio of less than 4:3 (roughly) when the preview is saved, the image will be skewed more prominently the closer to 4:3 the ratio gets. Once the ratio exceeds 4:3 (say 5:3), the image is no longer skewed.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

BillZndl

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #39 on: November 20, 2015, 09:44:28 AM »
Interesting .. considering I tested it with several open drawings and there was no issue. If it becomes an issue, I'd suggest checking the lock status prior to calling the GetBitmap method.

I don't get it either.

But thanks for the update.

Aw, geez, now I see I can download the file as my security settings have been changed by a blanket update on our computers.  :-(

BillZndl

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #40 on: November 20, 2015, 11:47:13 AM »
Just an FYI:

Here is the error I was getting before I checked for file lock.(attached .png)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: how to get preview dwg without autocad ?
« Reply #41 on: November 20, 2015, 04:47:51 PM »
Are you saying you CANNOT download the file?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

tetrahidrocannabinol

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #42 on: November 21, 2015, 10:40:35 PM »
Just an FYI:

Here is the error I was getting before I checked for file lock.(attached .png)

Weird, unless the other process use FileShare.None (CreateFile("fu", 0..), in any case acThumbnailPreview.GetBitmap looks right

BillZndl

  • Guest
Re: how to get preview dwg without autocad ?
« Reply #43 on: November 23, 2015, 06:22:17 AM »
Are you saying you CANNOT download the file?

Yes, cannot, sorry.


Edit:
I managed to change the settings so I can down load the file.
When I get time, I'll try it out.
Thanks again!

« Last Edit: November 23, 2015, 07:00:44 AM by BillZndl »