Capture brand new thumbnail of DWG on (side) database

Capture brand new thumbnail of DWG on (side) database

BestFriendCZ
Advocate Advocate
1,746 Views
5 Replies
Message 1 of 6

Capture brand new thumbnail of DWG on (side) database

BestFriendCZ
Advocate
Advocate

Hi all,
i would like to use similar command without opening document

 

db.ThumbnailBitmap = doc.CapturePreviewImage(height, width);

 

 

Did someone test this? or is it even possible?

 

 

...
0 Likes
Accepted solutions (1)
1,747 Views
5 Replies
Replies (5)
Message 2 of 6

BestFriendCZ
Advocate
Advocate

Hi all,

i would like to try update this question? Is there anybody who knows how to update document preview on database side (ReadDwgFile)?

 

Is there even possible (I spend some time on that and didn't find solution)?

...
0 Likes
Message 3 of 6

_gile
Consultant
Consultant

Hi,

 

You can get a DWG thumbnail from outide of AutoCAD.

Code inspired by this topic.

        static Bitmap GetBitmap(string fileName)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            using (BinaryReader br = new BinaryReader(fs))
            {
                fs.Seek(0xD, SeekOrigin.Begin);
                fs.Seek(0x14 + br.ReadInt32(), SeekOrigin.Begin);
                byte bytCnt = br.ReadByte();
                if (bytCnt <= 1)
                    return null;
                for (short i = 1; i <= bytCnt; i++)
                {
                    byte imageCode = br.ReadByte();
                    int imageHeaderStart = br.ReadInt32();
                    int imageHeaderSize = br.ReadInt32();
                    if (imageCode == 6)       //PNG Preview (2013 file format);
                    {
                        fs.Seek(imageHeaderStart, SeekOrigin.Begin);
                        using (var ms = new MemoryStream())
                        {
                            fs.CopyTo(ms, imageHeaderStart);
                            var img = Image.FromStream(ms);
                            return new Bitmap(img);
                        }
                    }
                }
            }
            return null;
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 6

BestFriendCZ
Advocate
Advocate

Hi _gile,

thank you for your feedback.

you are correct. Problem is that my question was not that specific ... sorry for that.

 

 

I know about this way how to read preview but i need capture brand new preview.

 

Situation like:

1) you do some changes on database side (changes which affect model)

2) and you need to create brand new thumbnail

 

I didn’t find way hot to achieve without open in CAD.... so i don’t know if it is even possible

...
0 Likes
Message 5 of 6

Norman_Yuan
Mentor
Mentor
Accepted solution

You question inspired me to write some code that could be the solution for you. I post the code in my block here:

 

https://drive-cad-with-code.blogspot.com/2022/08/generating-drawing-thumbnailpreview.html 

 

Hope it helps.

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 6

BestFriendCZ
Advocate
Advocate

Hi Norman,
this is exactly which i need it.
I spent lots of time trying to achieve something like that. Thank you

 

...
0 Likes