Inventor 2017 changed to Professional. Some macros does not work anymore.

Inventor 2017 changed to Professional. Some macros does not work anymore.

Anonymous
Not applicable
860 Views
7 Replies
Message 1 of 8

Inventor 2017 changed to Professional. Some macros does not work anymore.

Anonymous
Not applicable

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




0 Likes
Accepted solutions (2)
861 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor

Has your install language been changed to German to English?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 8

Anonymous
Not applicable

No. Language still german language pack and set to german.
Thats not the problem I think. If I change "Strukuriert" to "Structured" it doesn't change anything.

0 Likes
Message 4 of 8

bradeneuropeArthur
Mentor
Mentor

That's where I focused on too....

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 8

bradeneuropeArthur
Mentor
Mentor

try to put some messageboxes to see till what point the code runs!

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 6 of 8

Anonymous
Not applicable
Accepted solution

Problem 1 solved.
Was in another detail view. BOM runs only in "Main" view for details.
Change the code to change the view to main view bevor run.

But problem 2 still there if excel libery is active.

0 Likes
Message 7 of 8

Anonymous
Not applicable
Accepted solution

I solved the second problem, too.
Changed

Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns

To

Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Dim addIns As ApplicationAddIns 'Variable needed to be dimmed.
Set addIns = oApplication.ApplicationAddIns

I don't knew why, but in Inventor 2017 the macros still work without this changes. And they work with this changes in Inventor 2017 too. But in Professional they does only with the changes... There must be some changes in the vba for professional version of inventor...

Thanks guys for your help!

0 Likes
Message 8 of 8

bradeneuropeArthur
Mentor
Mentor

Hi,

 

This has to do with the Macro editor settings!!!!

 

Tools  >>> Options >>> 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes