Author Topic: Generate thumbnail silently  (Read 1891 times)

0 Members and 1 Guest are viewing this topic.

latour_g

  • Newt
  • Posts: 184
Generate thumbnail silently
« on: October 01, 2014, 11:55:39 AM »
Hi,
I'm trying to find a way to silently generate thumbnail for DWG that are only shown with the Dwg icon in Windows explorer.

I need to do this :
- open drawing
- set tilemode to 1 and do a zoom extent
- save drawing

So far here is what I have :

Code: [Select]
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;

            string cPathFile = @"C:\dwgWithNoPreview.dwg";

            using (Database dbase = new Database())
            {
                dbase.ReadDwgFile(cPathFile, System.IO.FileShare.ReadWrite, true, String.Empty);

                AcadApp.SetSystemVariable("TILEMODE", 1);
                MessageBox.Show(File.Exists(cPathFile).ToString());

                Object ActiveDoc = DocumentExtension.GetAcadDocument(doc);
                Object[] data = { "_zoom" + "\n" + "_e" + "\n" };
                ActiveDoc.GetType().InvokeMember("SendCommand", System.Reflection.BindingFlags.InvokeMethod, null, ActiveDoc, data);

                dbase.SaveAs(@"C:\dwgWithPreview.dwg", DwgVersion.Current);
            }



It does save the drawing but doesn't generate a thumbnail.  Also, I realize I am doing a zoom extent in my current drawing so I did try to change my code for that but with no success since it generate an error :


Code: [Select]
            string cPathFile = @"C:\dwgWithNoPreview.dwg";

            Document doc = AcadApp.DocumentManager.Open(cPathFile, false);  //  <-- Generate error
            Database db = doc.Database;

            AcadApp.SetSystemVariable("TILEMODE", 1);

            Object ActiveDoc = DocumentExtension.GetAcadDocument(doc);
            Object[] data = { "_zoom" + "\n" + "_e" + "\n" };
            ActiveDoc.GetType().InvokeMember("SendCommand", System.Reflection.BindingFlags.InvokeMethod, null, ActiveDoc, data);

            db.SaveAs(@"C:\test.dwg", DwgVersion.Current);           

I'm not use to play in drawing silently so I've been trying several thing since yesterday without success, some guidance would be helpful !






MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Generate thumbnail silently
« Reply #1 on: October 01, 2014, 04:36:22 PM »
I don't think you can use "SendCommand" with a drawing in memory as the SendCommand works within the open drawing in the UI.

You might have to do it the hard way and build the transformation manually, there is code in the help doc's and no doubt around here somewhere as an example.

hth
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.
- J.R.R. Tolkien

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Generate thumbnail silently
« Reply #2 on: October 03, 2014, 04:49:05 PM »
Can't be done "silently" within autocad because of the limitation in creating thumbnails.  If you want this done silently then use core console.

I wouldn't recommend the silent approach here since core console is still a bit twitchy, instead run an application command and open the documents, or scriptpro

To properly save with thumbnail you must go through the save command.