Need Help in using saveas function to save thumbnail image

Need Help in using saveas function to save thumbnail image

Anonymous
Not applicable
744 Views
2 Replies
Message 1 of 3

Need Help in using saveas function to save thumbnail image

Anonymous
Not applicable

Hi,

    Now I am facing a problem,I use database.SaveAs function to save a dwg file,but the dwg file do not have an thumbnail image,so I trid to search kean's blog ,and I write code like below,but I can't get what I want.

[CommandMethod("SendSaveAsCmd", CommandFlags.Session)]
        public static void DoSaveAs()
        {
            string filepath = @"C:\Users\FL_DRAWING\Desktop\Images\1.dwg";
            string targetpath = @"C:\Users\FL_DRAWING\Desktop\Images\newdwg.dwg";

            Document doc = Application.DocumentManager.Open(filepath, false);
            doc.LockDocument();
            Database db = doc.Database;
            object ocmd = Application.GetSystemVariable("CMDECHO");
            string newpath = targetpath.Replace("\\", "/");

            string cmd =
                "(setvar \"CMDECHO\" 0)" +
                "(command \"_.SAVEAS\" \"\" \"" + newpath + "\")" +
                "(setvar \"CMDECHO\" " + ocmd.ToString() + ")" +
                "(princ) ";
            doc.SendStringToExecute(cmd,false,false,false);

            doc.CloseAndDiscard();
        }

And I tried Another way like below

[CommandMethod("SaveThumbnail", CommandFlags.Session)]
        public static void DoSaveThumbnail()
        {
            string filepath = @"C:\Users\FL_DRAWING\Desktop\Images\1.dwg";
            string targetpath = @"C:\Users\FL_DRAWING\Desktop\Images\newdwg.dwg";

            Document doc = Application.DocumentManager.Open(filepath);
            doc.LockDocument();
            Database db = doc.Database;
            db.RetainOriginalThumbnailBitmap = true;
            Bitmap thumb = db.ThumbnailBitmap;
            db.ThumbnailBitmap = thumb;
            db.SaveAs(targetpath, DwgVersion.Current);
            doc.CloseAndDiscard();
        }

But the thumb is null in line Bitmap thumb = db.ThumbnailBitmap

In one of kean's blog ,I saw Document.CapturePreviewImage

So I rewrite my code like below

[CommandMethod("SaveThumbnail", CommandFlags.Session)]
        public static void DoSaveThumbnail()
        {
            string filepath = @"C:\Users\FL_DRAWING\Desktop\Images\1.dwg";
            string targetpath = @"C:\Users\FL_DRAWING\Desktop\Images\newdwg.dwg";

            Document doc = Application.DocumentManager.Open(filepath);
            doc.LockDocument();
            Database db = doc.Database;
            Bitmap thumb = doc.CapturePreviewImage(320, 240);
            db.ThumbnailBitmap = thumb;
            db.SaveAs(targetpath, DwgVersion.Current);
            doc.CloseAndDiscard();
        }

And I get a thumbnail image with a black background, but the thumbnail could not fullfill the thumbnail in Windows document viewer.And I also could not see cleer in Windows Document viewer.

 

Any help will be great, thank you.

0 Likes
745 Views
2 Replies
Replies (2)
Message 2 of 3

Virupaksha_aithal
Autodesk Support
Autodesk Support

Hi,

 

Try passing true for “bBakAndRename” in saveas API like

db.SaveAs(str, true, DwgVersion.Current, db.SecurityParameters); along with RetainOriginalThumbnailBitmap

Refer http://forums.autodesk.com/t5/net/retainoriginalthumbnailbitmap-not-working-for-replacing-the/td-p/6...



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

Anonymous
Not applicable

Hi,First I want to thank u for reply and I tried ur way but there is still another problem I try to build plenty of dwgs which has no thumbnail image,

if the dwg file has an thumbnail I use your method ,the anwser is yes,and I got a new dwg file with thumbnail,

but if the diw file has no thumbnail,and I tried,there is a dwg file I get without thumbnail.

 

Hope I am wrong and wish ur another anwser,thank u

0 Likes