Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to get image of ContentTreeViewNode.Icon

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
psaarloos
706 Views, 7 Replies

Trying to get image of ContentTreeViewNode.Icon

Hi All,

 

I am trying to get an image out of the ContentTreeViewNode.Icon property (IPictureDisp) in an Inventor add-in to display in a picturebox. I have red all available postings about converting an IPictureDisp to Image, but the conversion keep on failing. Does anybody has a working sample?

 

Thanks!

 

Regards,

Pim

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
7 REPLIES 7
Message 2 of 8

Hi Pim,

 

Here is a VBA sample that saves a node resource to the disk:

 

Sub Test()

    Dim PrtDoc As PartDocument
    Set PrtDoc = ThisApplication.ActiveDocument
    
    Dim oFea As PartFeature
    Set oFea = PrtDoc.ComponentDefinition.features(1)
    Dim oFeatureNativeBrowserNodeDef As NativeBrowserNodeDefinition
    Set oFeatureNativeBrowserNodeDef = PrtDoc.BrowserPanes.GetNativeBrowserNodeDefinition(oFea)
 
    Dim pic1 As stdole.IPictureDisp
    Set pic1 = oFeatureNativeBrowserNodeDef.Icon
    Call stdole.SavePicture(pic1, "C:\temp\Extrude.bmp")
     
End Sub

 

I hope it helps,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 8
psaarloos
in reply to: psaarloos

Hi Philippe,

Thanks for your feedback. I’ve seen a similar sample on the internet, but it’s a VBA sample. As noted in my question I am trying to get the image in an Inventor add-in. Every conversion from IPictureDisp to Image keeps on failing. Do you have a sample that works in an Inventor add-in as well?

Regards,
Pim
Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 4 of 8

I don't see why, the VBA code runs in-process and you should be able to invoke the same functions from an add-in... I'll give a try and let you know.

 

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 5 of 8

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

Message 6 of 8
psaarloos
in reply to: psaarloos

Hi Phillipe,

Thanks for the sample. I just realized that you're using another icon property than the one I am using. Did you try to use the code on the Content Center API? (The ContentTreeViewNode). That one particular gives an problem. I looks like the IPictureDisp type is not correct or something.

Regards,
Pim
Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 7 of 8
PiazzaD
in reply to: psaarloos

Maybe the problem is the IPictureDisp internally is an Icon and not a Bitmap. Check the field:

 

pictureDisp.Type

 

you can have one of the following values

 

'Picture Types
Public Const PICTYPE_UNINITIALIZED As Short = -1
Public Const PICTYPE_NONE As Short = 0
Public Const PICTYPE_BITMAP As Short = 1
Public Const PICTYPE_METAFILE As Short = 2
Public Const PICTYPE_ICON As Short = 3
Public Const PICTYPE_ENHMETAFILE As Short = 4

 

 

Daniele

 

Message 8 of 8

Hi Phillipe,

 

I tested your sample with the Content Center API and that seems to work. Strange thing though when I use a breakpoint on the line where I retrieve the Icon property, the code fails. If I just run in it works. I also tried again to convert the IPictureDisp to Image by using a couple of different functions that can be found on the internet, but also that still fails. Saving the icon as an temporary image file by the function you've provided and loading it again looks like the only working workflow.

 

Thanks for your help!  

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report