<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Get Part Icon iProperties in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/get-part-icon-iproperties/m-p/11276462#M139943</link>
    <description>&lt;P&gt;Hi, I have program for loading thumbnails from BOM in the visual studio (in the attachment). It works correctly. I have the same program for icons but it doesn't work. Can someone help me? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Imports System
Imports System.Type
Imports System.Activator
Imports System.Runtime.InteropServices
Imports System.Math
Imports System.IO
Imports Inventor

Public Class Form1

    Public Shared oInventor_App As Inventor.Application

    Private Sub Button_Load_BOM_Click(sender As Object, e As EventArgs) Handles Button_Load_BOM.Click

        '--------------------------------------------------------------------------------------

        Try

            'oInventor_App = GetObject(, "Inventor.Application")
            oInventor_App = Marshal.GetActiveObject("Inventor.Application")

        Catch ex As Exception

            MessageBox.Show("Musí byť spustený Autodesk Inventor!", "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

        '--------------------------------------------------------------------------------------

        Dim oStlpec_Ikona As New DataGridViewImageColumn()
        DataGridView_BOM.Columns.Add(oStlpec_Ikona)
        oStlpec_Ikona.HeaderText = ""
        oStlpec_Ikona.Name = "0"
        oStlpec_Ikona.ImageLayout = DataGridViewImageCellLayout.NotSet
        DataGridView_BOM.Columns("0").ReadOnly = True
        DataGridView_BOM.Columns("0").Visible = True

        DataGridView_BOM.Columns.Add("1", "Item")
        DataGridView_BOM.Columns("1").ReadOnly = True
        DataGridView_BOM.Columns("1").Visible = True

        Dim oStlpec_Nahlad_Modelu As New DataGridViewImageColumn()
        DataGridView_BOM.Columns.Add(oStlpec_Nahlad_Modelu)
        oStlpec_Nahlad_Modelu.HeaderText = "Thumbnail"
        oStlpec_Nahlad_Modelu.Name = "2"
        oStlpec_Nahlad_Modelu.ImageLayout = DataGridViewImageCellLayout.NotSet
        DataGridView_BOM.Columns("2").ReadOnly = True
        DataGridView_BOM.Columns("2").Visible = True


        '--------------------------------------------------------------------------------------

        If oInventor_App.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

            Dim oAsmDoc As AssemblyDocument
            oAsmDoc = oInventor_App.ActiveDocument

            Dim apprentice As New ApprenticeServerComponent
            Dim doc As ApprenticeServerDocument
            doc = apprentice.Open(oAsmDoc.FullFileName)

            Dim oBOM As BOM
            oBOM = doc.ComponentDefinition.BOM

            'Dim oBOM As BOM
            'oBOM = oAsmDoc.ComponentDefinition.BOM

            Dim oBOMView As BOMView
            oBOMView = oBOM.BOMViews.Item(1)

            Dim oBOMRow As BOMRow
            Dim oCompDef As ComponentDefinition

            For i = 1 To oBOMView.BOMRows.Count

                oBOMRow = oBOMView.BOMRows.Item(i)
                oCompDef = oBOMRow.ComponentDefinitions.Item(1)

                '--------------------------------------------------------------------------------------

                Dim oIcon As stdole.IPictureDisp
                oIcon = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Icon").Value

                '--------------------------------------------------------------------------------------

                Dim oImageIcon As System.Drawing.Image
                oImageIcon = IPictureDispConverter.PictureDispToImage(oIcon)

                Dim oBitmapIcon As New Bitmap(20, 20)
                Dim oImageIcon_Resize As System.Drawing.Graphics
                oImageIcon_Resize = Graphics.FromImage(oBitmapIcon)

                Try

                    oImageIcon_Resize.DrawImage(oImageIcon, 0, 0, 100, 100)

                Catch ex As Exception

                    'MsgBox(ex.ToString)

                End Try

                oIcon = Nothing
                oImageIcon = Nothing
                oImageIcon_Resize = Nothing

                '--------------------------------------------------------------------------------------

                Dim oThumbnail As stdole.IPictureDisp
                oThumbnail = Nothing

                For j = 1 To 1000

                    oThumbnail = oCompDef.Document.PropertySets.Item("Inventor Summary Information").Item("Thumbnail").Value

                    If oThumbnail.Handle &amp;gt; 0 Then

                        Exit For

                    End If

                Next

                '--------------------------------------------------------------------------------------

                Dim oImage As System.Drawing.Image
                oImage = IPictureDispConverter.PictureDispToImage(oThumbnail)

                Dim oBitmap As New Bitmap(100, 100)
                Dim oImage_Resize As System.Drawing.Graphics
                oImage_Resize = Graphics.FromImage(oBitmap)

                Try

                    oImage_Resize.DrawImage(oImage, 0, 0, 100, 100)

                Catch ex As Exception

                    'MsgBox(ex.ToString)

                End Try

                oThumbnail = Nothing
                oImage = Nothing
                oImage_Resize = Nothing

                '--------------------------------------------------------------------------------------

                DataGridView_BOM.Rows.Add(oBitmapIcon, i, oBitmap)

            Next

            doc.Close()

        End If

        '--------------------------------------------------------------------------------------

        oInventor_App = Nothing
        Button_Load_BOM.Enabled = False

    End Sub

End Class


'--------------------------------------------------------------------------------------

Public NotInheritable Class IPictureDispConverter : Inherits System.Windows.Forms.AxHost

    Private Sub New()

        MyBase.New("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")

    End Sub

    Public Shared Function PictureDispToImage(pictureDisp As Inventor.IPictureDisp) As Image

        Try

            Return GetPictureFromIPicture(pictureDisp)


        Catch ex As Exception

            'MsgBox(ex.ToString)
            Return Nothing

        End Try

    End Function

End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jul 2022 19:39:21 GMT</pubDate>
    <dc:creator>pavol_krasnansky</dc:creator>
    <dc:date>2022-07-04T19:39:21Z</dc:date>
    <item>
      <title>Get Part Icon iProperties</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/get-part-icon-iproperties/m-p/11276462#M139943</link>
      <description>&lt;P&gt;Hi, I have program for loading thumbnails from BOM in the visual studio (in the attachment). It works correctly. I have the same program for icons but it doesn't work. Can someone help me? Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Imports System
Imports System.Type
Imports System.Activator
Imports System.Runtime.InteropServices
Imports System.Math
Imports System.IO
Imports Inventor

Public Class Form1

    Public Shared oInventor_App As Inventor.Application

    Private Sub Button_Load_BOM_Click(sender As Object, e As EventArgs) Handles Button_Load_BOM.Click

        '--------------------------------------------------------------------------------------

        Try

            'oInventor_App = GetObject(, "Inventor.Application")
            oInventor_App = Marshal.GetActiveObject("Inventor.Application")

        Catch ex As Exception

            MessageBox.Show("Musí byť spustený Autodesk Inventor!", "Chyba", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

        '--------------------------------------------------------------------------------------

        Dim oStlpec_Ikona As New DataGridViewImageColumn()
        DataGridView_BOM.Columns.Add(oStlpec_Ikona)
        oStlpec_Ikona.HeaderText = ""
        oStlpec_Ikona.Name = "0"
        oStlpec_Ikona.ImageLayout = DataGridViewImageCellLayout.NotSet
        DataGridView_BOM.Columns("0").ReadOnly = True
        DataGridView_BOM.Columns("0").Visible = True

        DataGridView_BOM.Columns.Add("1", "Item")
        DataGridView_BOM.Columns("1").ReadOnly = True
        DataGridView_BOM.Columns("1").Visible = True

        Dim oStlpec_Nahlad_Modelu As New DataGridViewImageColumn()
        DataGridView_BOM.Columns.Add(oStlpec_Nahlad_Modelu)
        oStlpec_Nahlad_Modelu.HeaderText = "Thumbnail"
        oStlpec_Nahlad_Modelu.Name = "2"
        oStlpec_Nahlad_Modelu.ImageLayout = DataGridViewImageCellLayout.NotSet
        DataGridView_BOM.Columns("2").ReadOnly = True
        DataGridView_BOM.Columns("2").Visible = True


        '--------------------------------------------------------------------------------------

        If oInventor_App.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

            Dim oAsmDoc As AssemblyDocument
            oAsmDoc = oInventor_App.ActiveDocument

            Dim apprentice As New ApprenticeServerComponent
            Dim doc As ApprenticeServerDocument
            doc = apprentice.Open(oAsmDoc.FullFileName)

            Dim oBOM As BOM
            oBOM = doc.ComponentDefinition.BOM

            'Dim oBOM As BOM
            'oBOM = oAsmDoc.ComponentDefinition.BOM

            Dim oBOMView As BOMView
            oBOMView = oBOM.BOMViews.Item(1)

            Dim oBOMRow As BOMRow
            Dim oCompDef As ComponentDefinition

            For i = 1 To oBOMView.BOMRows.Count

                oBOMRow = oBOMView.BOMRows.Item(i)
                oCompDef = oBOMRow.ComponentDefinitions.Item(1)

                '--------------------------------------------------------------------------------------

                Dim oIcon As stdole.IPictureDisp
                oIcon = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Icon").Value

                '--------------------------------------------------------------------------------------

                Dim oImageIcon As System.Drawing.Image
                oImageIcon = IPictureDispConverter.PictureDispToImage(oIcon)

                Dim oBitmapIcon As New Bitmap(20, 20)
                Dim oImageIcon_Resize As System.Drawing.Graphics
                oImageIcon_Resize = Graphics.FromImage(oBitmapIcon)

                Try

                    oImageIcon_Resize.DrawImage(oImageIcon, 0, 0, 100, 100)

                Catch ex As Exception

                    'MsgBox(ex.ToString)

                End Try

                oIcon = Nothing
                oImageIcon = Nothing
                oImageIcon_Resize = Nothing

                '--------------------------------------------------------------------------------------

                Dim oThumbnail As stdole.IPictureDisp
                oThumbnail = Nothing

                For j = 1 To 1000

                    oThumbnail = oCompDef.Document.PropertySets.Item("Inventor Summary Information").Item("Thumbnail").Value

                    If oThumbnail.Handle &amp;gt; 0 Then

                        Exit For

                    End If

                Next

                '--------------------------------------------------------------------------------------

                Dim oImage As System.Drawing.Image
                oImage = IPictureDispConverter.PictureDispToImage(oThumbnail)

                Dim oBitmap As New Bitmap(100, 100)
                Dim oImage_Resize As System.Drawing.Graphics
                oImage_Resize = Graphics.FromImage(oBitmap)

                Try

                    oImage_Resize.DrawImage(oImage, 0, 0, 100, 100)

                Catch ex As Exception

                    'MsgBox(ex.ToString)

                End Try

                oThumbnail = Nothing
                oImage = Nothing
                oImage_Resize = Nothing

                '--------------------------------------------------------------------------------------

                DataGridView_BOM.Rows.Add(oBitmapIcon, i, oBitmap)

            Next

            doc.Close()

        End If

        '--------------------------------------------------------------------------------------

        oInventor_App = Nothing
        Button_Load_BOM.Enabled = False

    End Sub

End Class


'--------------------------------------------------------------------------------------

Public NotInheritable Class IPictureDispConverter : Inherits System.Windows.Forms.AxHost

    Private Sub New()

        MyBase.New("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")

    End Sub

    Public Shared Function PictureDispToImage(pictureDisp As Inventor.IPictureDisp) As Image

        Try

            Return GetPictureFromIPicture(pictureDisp)


        Catch ex As Exception

            'MsgBox(ex.ToString)
            Return Nothing

        End Try

    End Function

End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2022 19:39:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/get-part-icon-iproperties/m-p/11276462#M139943</guid>
      <dc:creator>pavol_krasnansky</dc:creator>
      <dc:date>2022-07-04T19:39:21Z</dc:date>
    </item>
  </channel>
</rss>

