The following code seems to work on my side. I'm attaching also the test project:
[DllImport(
"oleaut32.dll",
EntryPoint = "OleSavePictureFile",
ExactSpelling = true,
PreserveSig = false,
SetLastError = true)]
public static extern void OleSavePictureFile(
stdole.IPictureDisp Picture,
[MarshalAs(UnmanagedType.BStr)] string filename);
void SavePic(stdole.IPictureDisp pic, string dest)
{
string filename = System.IO.Path.GetTempFileName();
OleSavePictureFile(pic, filename);
System.Drawing.Image img = System.Drawing.Image.FromFile(
filename, true);
img.Save(dest,
System.Drawing.Imaging.ImageFormat.Png);
// exception temp file in use ...
//System.IO.File.Delete(filename);
}
public void Activate(
Inventor.ApplicationAddInSite addInSiteObject,
bool firstTime)
{
m_inventorApplication = addInSiteObject.Application;
PartDocument doc = m_inventorApplication.ActiveDocument as PartDocument;
var feature = doc.ComponentDefinition.Features[1];
var def = doc.BrowserPanes.GetNativeBrowserNodeDefinition(feature);
stdole.IPictureDisp pic = def.Icon;
SavePic(pic, @"C:\Temp\icon.png");
}
Philippe.
Philippe Leefsma
Developer Technical Services
Autodesk Developer Network