Hi Roland
anbei vielleicht etwas was dir die Vorgehensweise erleichtert.
Dieses Makro erstellt im Ordner der Baugruppe einen Unterordner (BOM_XLS).
Dort werden 2 Exceldateien erstellt einmal Struktur einmal nur Teile.
Diese haben den Namen der
Baugruppe + BOM-StructuredAllLevels.xls
&
Baugruppe + "BOM-PartsOnly.xls"
Dies auf einen Knopf als User Tool und du hast schon mal einen sauberen Ansatz.
Kann man natürlich auch als Ilogic Regel beim Speichern laufen lassen
*****************************************
Public Sub BOMExport2file()
' Set a reference to the assembly document.
' This assumes an assembly document is active.
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
'Get filename
Dim ftempname As String
ftempname = Filename(oDoc.fullFilename)
Dim ftempdir As String
ftempdir = FilePath(oDoc.fullFilename) & "\BOM_XLS\"
Dim resname As String
resname = ftempdir & ftempname
'check dir & kill old file
On Error Resume Next
MkDir (ftempdir)
Kill resname
On Error GoTo 0
' Set a reference to the BOM
Dim oBOM As Inventor.BOM
Set oBOM = oDoc.ComponentDefinition.BOM
' Set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
' Set a reference to the "Structured" BOMView
Dim oStructuredBOMView As BOMView
Set oStructuredBOMView = oBOM.BOMViews.Item("Structured")
' Export the BOM view to an Excel file
oStructuredBOMView.Export (resname & "BOM-StructuredAllLevels.xls"), kMicrosoftExcelFormat
' Make sure that the parts only view is enabled.
oBOM.PartsOnlyViewEnabled = True
' Set a reference to the "Parts Only" BOMView
Dim oPartsOnlyBOMView As BOMView
Set oPartsOnlyBOMView = oBOM.BOMViews.Item("Parts Only")
' Export the BOM view to an Excel file
oPartsOnlyBOMView.Export (resname & "BOM-PartsOnly.xls"), kMicrosoftExcelFormat
End Sub
Public Function FilePath(ByVal fullFilename As String) As String
' Extract the path by getting everything up to and
' including the last backslash "\".
FilePath = Left$(fullFilename, InStrRev(fullFilename, "\") - 1)
End Function
Public Function Filename(ByVal fullFilename As String) As String
' Extract the filename by getting everything to
' the right of the last backslash.
Filename = Right$(fullFilename, Len(fullFilename) - InStrRev(fullFilename, "\"))
'InStrRev(fullFilename, "\"))
End Function
------------------
"Das Motto des Tages"
Wir hatten nie 'ne Schulung in Inventor
Wir hatten nie 'ne Schulung in Methodik
Wir haben keinen Wartungsvertrag
Wir haben keinen Admin
Wir haben trotzdem Spaß!
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP