iLogic BOMView

iLogic BOMView

Reitshammer
Explorer Explorer
448 Views
6 Replies
Message 1 of 7

iLogic BOMView

Reitshammer
Explorer
Explorer

Hallo,

 

kann mir vielleicht jemand bei meinem Code helfen.

Ich habe aktuell das Problem mit dir Stückliste "Part Only"

Ich möchte aus dieser Stückliste von jedem Bauteil z.B. nur die Bauteilnummer Exportieren.

 

Anbei der Code den ich jetzt habe.

 

Dim myXLS_File As String = "C:\Vault\Vorlage.xlsx"

' Den Inventor-Benutzernamen aus den Inventor-Optionen
Dim myName As String = ThisApplication.GeneralOptions.UserName

' iProperties auslesen
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim Projekt As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Project").Value
Dim Dateiname As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
Dim Beschreibung As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
Dim Datum As String = DateTime.Now.ToString("dd.MM.yyyy")

' Abrufen des Konstruktionsstatus aus den iProperties
Dim designStatus As Integer = oDoc.PropertySets.Item("Design Tracking Properties").Item("Design Status").Value
Dim statusText As String

' Überprüfen des Design Status und Zuweisen des entsprechenden Textes
If designStatus = 1 Then
    statusText = "Freigegeben"
ElseIf designStatus = 0 Then
    statusText = "In Bearbeitung"
End If

' Excel-Anwendungsobjekt definieren
Dim excelApp As Object = CreateObject("Excel.Application")
' Stellen Sie Excel so ein, dass es sichtbar ausgeführt wird. Ändern Sie es in „false“, wenn Sie es unsichtbar ausführen möchten.
excelApp.Visible = True
' Eingabeaufforderungen unterdrücken (wie etwa den Kompatibilitätsprüfer)
excelApp.DisplayAlerts = False

' Nach vorhandener Datei suchen
Dim excelWorkbook As Object
Dim ExcelSheet As Object
If Dir(myXLS_File) <> "" Then
    ' Arbeitsmappe existiert, öffnen Sie sie
    excelWorkbook = excelApp.Workbooks.Open(myXLS_File)
    ExcelSheet = excelWorkbook.Worksheets(1)
Else
    ' Arbeitsmappe existiert NICHT, also erstellen Sie eine neue
    excelWorkbook = excelApp.Workbooks.Add
    ExcelSheet = excelWorkbook.Worksheets(1)
End If

' Daten in Excel einfügen
With ExcelSheet
    .Range("J1").Value = myName
    .Range("F1").Value = Projekt
    .Range("F2").Value = Dateiname
    .Range("F3").Value = Beschreibung
    .Range("J2").Value = Datum
    .Range("J3").Value = statusText
End With

' Die Stückliste (BOM) abrufen
Dim asmDoc As AssemblyDocument = TryCast(oDoc, AssemblyDocument)
If asmDoc Is Nothing Then
    MessageBox.Show("Das aktive Dokument ist keine Baugruppe.")
    Return
End If

Dim bom As BOM = asmDoc.ComponentDefinition.BOM
bom.StructuredViewFirstLevelOnly = False
bom.StructuredViewEnabled = True

' Die "Part Only"-Stücklistenansicht abrufen
Dim bomView As BOMView = BOM.BOMViews.Item("Part Only")



' Stücklistenzeilen in Excel schreiben
Dim rowIndex As Integer = 7
For Each BOMRow As BOMRow In BOMView.BOMRows
    ExcelSheet.Cells(rowIndex, 1).Value = BOMRow.ItemNumber
    ExcelSheet.Cells(rowIndex, 2).Value = BOMRow.ComponentDefinitions(1).Document.DisplayName
    ExcelSheet.Cells(rowIndex, 3).Value = BOMRow.ItemQuantity
    rowIndex += 1
Next

' Speichern Sie die Datei
Dim Pfad As String = ThisDoc.Path + "\Stückliste-" + ThisDoc.FileName(False) + ".xlsx"
excelWorkbook.SaveAs(Pfad)

' Schließen Sie die Arbeitsmappe und die Excel-Anwendung
' Entfernen Sie die Kommentarzeichen, wenn Sie die xls-Datei am Ende schließen möchten
excelWorkbook.Close
excelApp.Quit
excelApp = Nothing
0 Likes
Accepted solutions (4)
449 Views
6 Replies
Replies (6)
Message 2 of 7

marcin_otręba
Advisor
Advisor
Accepted solution

you have error here:

in english it should be Parts Only  but if you use german version it will not work.

Dim bomView As BOMView = BOM.BOMViews.Item("Part Only")

it should be :

first of all use:

bom.PartsOnlyViewEnabled =True

 

then use german name of this view or better use number intead:

1 - model 

2 - structured

3 - parts only

 

Dim bomView As BOMView = BOM.BOMViews.Item(3)

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 7

Reitshammer
Explorer
Explorer

Hello,

Thank you for the quick response and assistance. It worked perfectly. However, I now have another issue. When I export my custom properties, I encounter an error whenever I come across a standard part from the Content Center. This is likely because these properties do not exist in the part. Is there a way to simply skip this step?

 

' Definieren Sie die zu erstellende/öffnende Datei
' ThisDoc.Save

Dim myXLS_File As String = "C:\Vault\Vorlage.xlsx"

' Den Inventor-Benutzernamen aus den Inventor-Optionen
Dim myName As String = ThisApplication.GeneralOptions.UserName

' iProperties auslesen
Dim oDoc As Document = ThisApplication.ActiveDocument
Dim Projekt As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Project").Value
Dim Dateiname As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
Dim Beschreibung As String = oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value
Dim Datum As String = DateTime.Now.ToString("dd.MM.yyyy")

' Abrufen des Konstruktionsstatus aus den iProperties
Dim designStatus As Integer = oDoc.PropertySets.Item("Design Tracking Properties").Item("Design Status").Value
Dim statusText As String

' Überprüfen des Design Status und Zuweisen des entsprechenden Textes
If designStatus = 1 Then
    statusText = "Freigegeben"
ElseIf designStatus = 0 Then
    statusText = "In Bearbeitung"
End If

' Excel-Anwendungsobjekt definieren
Dim excelApp As Object = CreateObject("Excel.Application")
' Stellen Sie Excel so ein, dass es sichtbar ausgeführt wird. Ändern Sie es in „false“, wenn Sie es unsichtbar ausführen möchten.
excelApp.Visible = True
' Eingabeaufforderungen unterdrücken (wie etwa den Kompatibilitätsprüfer)
excelApp.DisplayAlerts = False

' Nach vorhandener Datei suchen
Dim excelWorkbook As Object
Dim ExcelSheet As Object
If Dir(myXLS_File) <> "" Then
    ' Arbeitsmappe existiert, öffnen Sie sie
    excelWorkbook = excelApp.Workbooks.Open(myXLS_File)
    ExcelSheet = excelWorkbook.Worksheets(1)
Else
    ' Arbeitsmappe existiert NICHT, also erstellen Sie eine neue
    excelWorkbook = excelApp.Workbooks.Add
    ExcelSheet = excelWorkbook.Worksheets(1)
End If

' Daten in Excel einfügen
With ExcelSheet
    .Range("J1").Value = myName
    .Range("F1").Value = Projekt
    .Range("F2").Value = Dateiname
    .Range("F3").Value = Beschreibung
    .Range("J2").Value = Datum
    .Range("J3").Value = statusText
End With

' Die Stückliste (BOM) abrufen
Dim asmDoc As AssemblyDocument = TryCast(oDoc, AssemblyDocument)
If asmDoc Is Nothing Then
    MessageBox.Show("Das aktive Dokument ist keine Baugruppe.")
    Return
End If

Dim bom As BOM = asmDoc.ComponentDefinition.BOM
bom.StructuredViewFirstLevelOnly = False
bom.PartsOnlyViewEnabled = True

' Die "Part Only"-Stücklistenansicht abrufen
Dim bomView As BOMView = bom.BOMViews.Item(3)



' Stücklistenzeilen in Excel schreiben
Dim rowIndex As Integer = 7
For Each BOMRow As BOMRow In BOMView.BOMRows
    ExcelSheet.Cells(rowIndex, 1).Value = BOMRow.ItemNumber
    ExcelSheet.Cells(rowIndex, 2).Value = BOMRow.ComponentDefinitions(1).Document.PropertySets(3).ItemByPropId(5).Value
	ExcelSheet.Cells(rowIndex, 4).Value = BOMRow.ItemQuantity
	ExcelSheet.Cells(rowIndex, 5).Value = BOMRow.ComponentDefinitions(1).Document.PropertySets("Design Tracking Properties")("Description").Value
	ExcelSheet.Cells(rowIndex, 6).Value = BOMRow.ComponentDefinitions(1).Document.PropertySets("Design Tracking Properties")("Material").Value
	ExcelSheet.Cells(rowIndex, 7).Value = BOMRow.ComponentDefinitions(1).Document.PropertySets("User Defined Properties")("Oberfläche").Value
	ExcelSheet.Cells(rowIndex, 9).Value = BOMRow.ComponentDefinitions(1).Document.PropertySets("User Defined Properties")("Rohteilabmaße").Value
	ExcelSheet.Cells(rowIndex, 10).Value = BOMRow.ComponentDefinitions(1).Document.PropertySets("Design Tracking Properties")("Document SubType").Value
	ExcelSheet.Cells(rowIndex, 11).Value = BOMRow.ComponentDefinitions(1).Document.PropertySets("Design Tracking Properties")("Vendor").Value
	ExcelSheet.Cells(rowIndex, 13).Value = BOMRow.ComponentDefinitions(1).Document.DisplayName
    rowIndex +=  1
Next

' Speichern Sie die Datei
Dim Pfad As String = ThisDoc.Path + "\Stückliste-" + ThisDoc.FileName(False) + ".xlsx"
excelWorkbook.SaveAs(Pfad)

' Schließen Sie die Arbeitsmappe und die Excel-Anwendung
' Entfernen Sie die Kommentarzeichen, wenn Sie die xls-Datei am Ende schließen möchten
excelWorkbook.Close
excelApp.Quit
excelApp = Nothing
0 Likes
Message 4 of 7

marcin_otręba
Advisor
Advisor
Accepted solution

You need some error handling in your code use try catch statements

or place:  

 

on errror resume next

 

in first line of your code. This will skip line if error occur.

 

You can check document type and if it is CC then skip some lines of code etc.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 7

Reitshammer
Explorer
Explorer

Hello, Could you please help me export a thumbnail? I am having trouble converting the IPicture to a BMP in iLogic. I would really appreciate your help. Thank you very much!

0 Likes
Message 6 of 7

william
Advocate
Advocate
Accepted solution

This is what I use to generate the thumbnail views. 

It's less complicated than trying to access the thumbnail image stored against the BOM item. 

 

For Each bRow In oBOMRows
	Dim rDoc As Document = bRow.ComponentDefinitions.Item(1).Document
        strThumbnailPath = "C:\Downloads\" & rDoc.DisplayName & ".jpg"
	rDoc.SaveAs(strThumbnailPath, True)
Next

 

 

0 Likes
Message 7 of 7

marcin_otręba
Advisor
Advisor
Accepted solution

Hi,

 

you can easily find solution on this forum, for example check this one:

 

Solved: Save thumbnail as image file - Autodesk Community

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes