Get a thumbnail of any file, including SolidWorks in Windows XP / Vista

Each installed OS has many built-in ThumbnailProviders. Thanks to these providers, Windows can display Thumbnail from many files. For example, Windows Explorer can display the contents of * .jpg files, but also from SolidWorks * .sldprt files (if SolidWorks is installed).

But is there any way to get these sketches? I tried to manage this using the Windows API CodecPack, but I only succeeded in Windows 7.

ShellFile shellFile = ShellFile.FromFilePath(filePath); Bitmap shellThumb = shellFile.Thumbnail.Bitmap; 

Question: is there any other way to get thumbnails of any file with a registered thumbnail provider in Windows XP / Vista? I'm really desperate ...

+7
source share
2 answers

There are several ways:

1) With the OpenMCDF library. Solidworks file A compound document , so access to its contents is a parsing of the file.

  OpenFileDialog dialog = new OpenFileDialog(); dialog.InitialDirectory = Application.StartupPath; if (dialog.ShowDialog() == DialogResult.OK) { string STORAGE_NAME = dialog.FileName.ToString(); CompoundFile cf = new CompoundFile(STORAGE_NAME); CFStream st = cf.RootStorage.GetStream("PreviewPNG"); byte[] buffer = st.GetData(); var ms = new MemoryStream(buffer.ToArray()); pictureBox1.Image = Image.FromStream(ms); } 

2) With the library EModelView.dll, which will be added as a control and placed on the form.

  OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { axEModelViewControl1.OpenDoc(dialog.FileName.ToString(), false, false, true, ""); } 

3) With SWExplorer library (wpfPreviewFlowControl)

  OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { string sDocFileName = dialog.FileName.ToString(); wpfThumbnailCreator pvf; pvf = new wpfThumbnailCreator(); System.Drawing.Size size = new Size(); size.Width = 200; size.Height = 200; pvf.DesiredSize = size; System.Drawing.Bitmap pic = pvf.GetThumbNail(sDocFileName); pictureBox1.Image = pic; } 

3) With the Document Manager library (SolidWorks.Interop.swdocumentmgr)

  OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { string sDocFileName = dialog.FileName.ToString(); SwDMClassFactory swClassFact = default(SwDMClassFactory); SwDMApplication swDocMgr = default(SwDMApplication); SwDMDocument swDoc = default(SwDMDocument); SwDMConfigurationMgr swCfgMgr = default(SwDMConfigurationMgr); string[] vCfgNameArr = null; SwDMConfiguration7 swCfg = default(SwDMConfiguration7); IPictureDisp pPreview = default(IPictureDisp); SwDmDocumentType nDocType = 0; SwDmDocumentOpenError nRetVal = 0; SwDmPreviewError nRetVal2 = 0; Image image = default(Image); //Access to interface swClassFact = new SwDMClassFactory(); swDocMgr = (SwDMApplication)swClassFact.GetApplication("Post your code here"); swDoc = (SwDMDocument)swDocMgr.GetDocument(sDocFileName, nDocType, false, out nRetVal); Debug.Assert(SwDmDocumentOpenError.swDmDocumentOpenErrorNone == nRetVal); swCfgMgr = swDoc.ConfigurationManager; pathLabel.Text = "Path to file: " + swDoc.FullName; configLabel.Text = "Active config: " + swCfgMgr.GetActiveConfigurationName(); vCfgNameArr = (string[])swCfgMgr.GetConfigurationNames(); foreach (string vCfgName in vCfgNameArr) { //get preview swCfg = (SwDMConfiguration7)swCfgMgr.GetConfigurationByName(vCfgName); pPreview = (IPictureDisp)swCfg.GetPreviewPNGBitmap(out nRetVal2); image = Support.IPictureDispToImage(pPreview); //insert to picturebox pictureBox1.BackgroundImage = image; } swDoc.CloseDoc(); } 
+5
source

You can use the unmanaged methods of the Windows shell to get a sketch

Here is the code (not small)

But the results are far from perfect.

  • Debugging is very complex, an undefined error is common.
  • the target computer must have a special file reader (for example, a PDF reader for PDF files, I have not tried it on SolidWorks).
  • can only work on windows
  • performance issue
  • low quality thumbnails (tried it with pdf)
-one
source

All Articles