I'm developing C# VSTA macro for our manufacturing department.
I'm using SldWorks.GetPreviewBitMapFile
to save a bitmap preview of the selected model and show it in the picturebox as shown below:
The code looks fine and execute fine except for the strange colors:
bool status = swApp.GetPreviewBitmapFile(filepath, configuration, "D:\\preview.bmp");
pictureBox1.ImageLocation = "D:\\Preview.bmp";
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Refresh();
Has anyone had a similar problem and what's the remedy?
Here is an example of working code:
//to compare output
iSwApp.GetPreviewBitmapFile(@"c:\Path\Part1.SLDPRT", "Default", @"c:\Path\Part1_0.bmp");
object com = iSwApp.GetPreviewBitmap(@"c:\Path\Part1.SLDPRT", "Default");
stdole.StdPicture pic = com as stdole.StdPicture;
Bitmap bmp = Bitmap.FromHbitmap((IntPtr)pic.Handle);
bmp.Save(@"c:\Path\Part1_1.bmp");
There are few notes about GetPreviewBitmap from SW API:
I was able to make it work in SolidWorks x64 only in .NET add-in and in VBA macros. Let me know if you need add-in example.