
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I have a problem with Inventor.
I have a PC with Inventor 2017 installed and use some macros for my work. Now I have a PC with Inventor Professional 2017. The same macros are installed. But they do not work anymore.
1. First problem
The first macro is a simple macro to output my BOM. Here he complains in the lines (Complete macro below):
Error: "Run-time error 5: Invalid procedire call arguement"
'Set a reference to the "Structured" BOMView Dim oBOMView As BOMView Set oBOMView = oBOM.BOMViews.Item("Strukturiert")
and in line
Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab, xlApp, xlwb, xlws, oStartRow)
Complete macro for BOM output:
Public Sub BOM_Export() ' Set a reference to the assembly document. ' This assumes an assembly document is active. Dim oDoc As AssemblyDocument Set oDoc = ThisApplication.ActiveDocument Dim oTemplate As String: oTemplate = "C:\Template.xlsx" ' Set a reference to the BOM Dim oBOM As BOM Set oBOM = oDoc.ComponentDefinition.BOM ' Set whether first level only or all levels. oBOM.StructuredViewFirstLevelOnly = False ' Make sure that the structured view is enabled. oBOM.StructuredViewEnabled = True 'Set a reference to the "Structured" BOMView Dim oBOMView As BOMView Set oBOMView = oBOM.BOMViews.Item("Strukturiert") Dim oPartNumProperty As String oPartNumProperty = oDoc.ComponentDefinition.Document.PropertySets( _ "Design Tracking Properties")("Part Number").Value Dim oPartRevNum As String oPartRevNum = oDoc.ComponentDefinition.Document.PropertySets( _ "Inventor Summary Information")("Revision Number").Value Dim oPartTitle As String oPartTitle = oDoc.ComponentDefinition.Document.PropertySets( _ "Inventor Summary Information")("Title").Value ' set excel app and add worksheet Dim xlApp As Object Dim xlwb As Object Dim xlws As Object Set xlApp = CreateObject("Excel.Application") Set xlwb = xlApp.Workbooks.Open(oTemplate) 'Set xlwb = xlApp.workbooks.Add Set xlws = xlwb.Worksheets(1) xlApp.Visible = True ' write more stuff xlws.Cells(1, 2) = oPartTitle xlws.Cells(1, 3) = oPartNumProperty xlws.Cells(1, 4) = "Rev: " & oPartRevNum xlws.name = "Stückliste " & oPartNumProperty 'Initialize the tab for ItemNumber Dim ItemTab As Long ItemTab = -3 Dim oStartRow As Integer: oStartRow = 4 Call QueryBOMRowProperties(oBOMView.BOMRows, ItemTab, xlApp, xlwb, xlws, oStartRow) End Sub Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator, ItemTab As Long, ByVal xlApp As Object, ByVal xlwb As Object, ByVal xlws As Object, oStartRow As Integer) ItemTab = ItemTab + 3 ' Iterate through the contents of the BOM Rows. Dim i As Long For i = 1 To oBOMRows.Count ' Get the current row. Dim oRow As BOMRow Set oRow = oBOMRows.Item(i) 'Set a reference to the primary ComponentDefinition of the row Dim oCompDef As ComponentDefinition Set oCompDef = oRow.ComponentDefinitions.Item(1) Dim oPartNumProperty As Property Dim oPartStockNumProperty As Property Dim oPartCategory As Property Dim oPartTitle As Property Dim oPartWidth As Property Dim oPartHeight As Property Dim oPartLength As Property If TypeOf oCompDef Is VirtualComponentDefinition Then Set oPartNumProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Part Number") Set oPartStockNumProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Stock Number") Set oPartTitle = oCompDef.Document.PropertySets _ .Item("Inventor Summary Information").Item("Title") On Error Resume Next Set oPartWidth = oCompDef.Document.PropertySets _ .Item("Inventor User Defined Properties").Item("Breite") On Error Resume Next Set oPartHeight = oCompDef.Document.PropertySets _ .Item("Inventor User Defined Properties").Item("Höhe") On Error Resume Next Set oPartLength = oCompDef.Document.PropertySets _ .Item("Inventor User Defined Properties").Item("Länge") 'Get the file property that contains the "Description" Set oDescripProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Description") Set oPartCategory = oCompDef.Document.PropertySets _ .Item("Inventor Document Summary Information").Item("Category") xlws.Cells(oStartRow + b, 1) = oRow.ItemNumber xlws.Cells(oStartRow + b, 2) = oPartCategory.Value xlws.Cells(oStartRow + b, 3) = oPartStockNumProperty.Value xlws.Cells(oStartRow + b, 4) = oPartTitle.Value xlws.Cells(oStartRow + b, 5) = oPartNumProperty.Value xlws.Cells(oStartRow + b, 6) = oPartWidth.Value xlws.Cells(oStartRow + b, 7) = oPartHeight.Value xlws.Cells(oStartRow + b, 8) = oPartLength.Value xlws.Cells(oStartRow + b, 9) = oCompDef.BOMQuantity.UnitQuantity xlws.Cells(oStartRow + b, 10) = oRow.ItemQuantity oStartRow = oStartRow + 1 Else 'Get the file property that contains the "Part Number" 'The file property is obtained from the parent 'document of the associated ComponentDefinition. ' write more stuff Set oPartNumProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Part Number") Set oPartStockNumProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Stock Number") Set oPartTitle = oCompDef.Document.PropertySets _ .Item("Inventor Summary Information").Item("Title") On Error Resume Next Set oPartWidth = oCompDef.Document.PropertySets _ .Item("Inventor User Defined Properties").Item("Breite") On Error Resume Next Set oPartHeight = oCompDef.Document.PropertySets _ .Item("Inventor User Defined Properties").Item("Höhe") On Error Resume Next Set oPartLength = oCompDef.Document.PropertySets _ .Item("Inventor User Defined Properties").Item("Länge") 'Get the file property that contains the "Description" Set oDescripProperty = oCompDef.Document.PropertySets _ .Item("Design Tracking Properties").Item("Description") Set oPartCategory = oCompDef.Document.PropertySets _ .Item("Inventor Document Summary Information").Item("Category") xlws.Cells(oStartRow + b, 1) = oRow.ItemNumber xlws.Cells(oStartRow + b, 2) = oPartCategory.Value xlws.Cells(oStartRow + b, 3) = oPartStockNumProperty.Value xlws.Cells(oStartRow + b, 4) = oPartTitle.Value xlws.Cells(oStartRow + b, 5) = oPartNumProperty.Value xlws.Cells(oStartRow + b, 6) = oPartWidth.Value xlws.Cells(oStartRow + b, 7) = oPartHeight.Value xlws.Cells(oStartRow + b, 8) = oPartLength.Value xlws.Cells(oStartRow + b, 9) = oCompDef.BOMQuantity.UnitQuantity xlws.Cells(oStartRow + b, 10) = oRow.ItemQuantity oStartRow = oStartRow + 1 Debug.Print Tab(ItemTab); oRow.ItemNumber; Tab(17); oRow.ItemQuantity; Tab(30); _ oPartNumProperty.Value; Tab(70); oDescripProperty.Value 'Recursively iterate child rows if present. If Not oRow.ChildRows Is Nothing Then Call QueryBOMRowProperties(oRow.ChildRows, ItemTab, xlApp, xlwb, xlws, oStartRow) End If End If Next ItemTab = ItemTab - 3 End Sub
Thats the first problem.
2. Second problem
The second problem is that I need to enable the Excel library for the BOM export macro. If I activate this, another macro will not work anymore.
A macro with which I can execute an iLogic rule via the macro.
Error: "Compile error: Invalid use of property"
In Line:
Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Complete iLogic macro
Public Sub RunGlobaliLogic(ByVal RuleName As String) Dim iLogicAuto As Object Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument If oDoc Is Nothing Then MsgBox "Missing Inventor Document" Exit Sub End If Set iLogicAuto = GetiLogicAddin(ThisApplication) If (iLogicAuto Is Nothing) Then Exit Sub iLogicAuto.RunExternalRule oDoc, RuleName End Sub Public Sub RunInternaliLogic(ByVal RuleName As String) Dim iLogicAuto As Object Dim oDoc As Document Set oDoc = ThisApplication.ActiveDocument If oDoc Is Nothing Then MsgBox "Missing Inventor Document" Exit Sub End If Set iLogicAuto = GetiLogicAddin(ThisApplication) If (iLogicAuto Is Nothing) Then Exit Sub iLogicAuto.RunRule oDoc, RuleName End Sub Function GetiLogicAddin(oApplication As Inventor.Application) As Object Set addIns = oApplication.ApplicationAddIns 'Find the add-in you are looking for Dim addIn As ApplicationAddIn On Error GoTo NotFound Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}") If (addIn Is Nothing) Then Exit Function addIn.Activate Set GetiLogicAddin = addIn.Automation Exit Function NotFound: End Function
Solved! Go to Solution.