Message 1 of 1
Get Part Icon iProperties
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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 > 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