How to link Excel VBA with parameterization to Inventor VBA?

How to link Excel VBA with parameterization to Inventor VBA?

ThyagoVicent
Contributor Contributor
715 Views
3 Replies
Message 1 of 4

How to link Excel VBA with parameterization to Inventor VBA?

ThyagoVicent
Contributor
Contributor

Is it possible to link a parameterization made in Excel with Inventor's VBA?

I have performed parameterization of a machine in Inventor using Excel, in which when a measurement is changed in Excel, the machine adjusts its dimensions accordingly. However, I would like to implement this in VBA so that when Excel is opened, only the dimension fields that need to be changed are visible, and then the changes can be saved, the VBA closed, and the designer can open the Inventor file to see the changes in the project. Alternatively, if it is possible to incorporate this into Inventor's VBA, a VBA window could appear upon opening the project to modify the dimensions.

Thank you in advance.

0 Likes
716 Views
3 Replies
Replies (3)
Message 2 of 4

Crstiano
Collaborator
Collaborator

You can use the Parameters command to link with excel file.

After just use the variables where you desire.

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Cristiano Oliveira
EESignature
ConsultCAD.com

Message 3 of 4

A.Acheson
Mentor
Mentor

Hi @ThyagoVicent 

As @Crstiano suggest using the built in parameter linking with excel is one route. It can be a little inflexible depending on where your data is stored, the units etc. 

 

Another method is using ilogic editor and ilogic API and go excel you can point  to a cell and import the data. 

Parameter("d5") = GoExcel.CellValue("filename.xlsx", "SheetName", "Cell")
iLogicVb.UpdateWhenDone = True

 

The hardest method is using inventor VBA. The reason being it uses Inventor API.  Open Excel and reference excel workbook and point to a cell and import parameters. 

Getting data from excel sample here.

Setting a parameter value from Inventor API Help here.

 

 

You can ask programming questions on the dedicated forum here

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 4 of 4

tonythm
Advocate
Advocate

Hello @ThyagoVicent 

 

I think, you should use function available in Inventor.
Or you can use below VBA code, I'm really not good at VBA but I can only write what I know.
You can create a VBA that can run multiple .*ipt updates in .*iam.

 

Capture.JPG

 

Sub CreateParam()
    Dim oWkbk As Workbook
    Set oWkbk = ThisWorkbook
    Dim oSheet As Worksheet
    Set oSheet = oWkbk.ActiveSheet
    Dim oCell As Range
    oLastRow = oSheet.Cells(oSheet.Rows.Count, 1).End(XlDirection.xlUp).Row
    Dim oInv As Inventor.Application
    Set oInv = GetObject(, "Inventor.Application")
    Dim oDoc As Document
    Set oDoc = oInv.ActiveDocument
    Dim partDoc As PartDocument
    Set partDoc = oInv.ActiveDocument
    Dim userParams As UserParameters
    Set userParams = partDoc.ComponentDefinition.Parameters.UserParameters
    a = "A"
    i = 0
    For Each oCell In Range(a & i + 3, a & oLastRow)
        Dim param As Parameter
        On Error Resume Next
        Set param = userParams.AddByExpression(oCell, oCell.Offset(0, 1).Value, oCell.Offset(0, 2).Value)
        If Err.Number <> 0 Then
        On Error Resume Next
        End If
        Dim oUserParam As UserParameter
        For Each oUserParam In userParams
            Dim oLen As Variant
            oLen = Len(oUserParam.name)
            'If oLen <> 5 Then
                'oUserParam.Delete
            'End If
            If oUserParam.name = oCell.Value Then
                oUserParam.Comment = oCell.Offset(, 3)
            End If
        Next
    Next oCell
    MsgBox "Done!"
End Sub

 

Sub UpdateParam()
    Dim oWkbk As Workbook
    Set oWkbk = ThisWorkbook
    Dim oSheet As Worksheet
    Set oSheet = oWkbk.ActiveSheet
    Dim oCell As Range
    oLastRow = oSheet.Cells(oSheet.Rows.Count, 1).End(XlDirection.xlUp).Row
    Dim oInv As Inventor.Application
    Set oInv = GetObject(, "Inventor.Application")
    Dim oDoc As Document
    Set oDoc = oInv.ActiveDocument
    Dim partDoc As PartDocument
    Set partDoc = oInv.ActiveDocument
    a = "A"
    i = 0
    For Each oCell In Range(a & i + 3, a & oLastRow)
        Dim userParams As UserParameters
        Set userParams = partDoc.ComponentDefinition.Parameters.UserParameters
        Dim oUserParam As UserParameter
        For Each oUserParam In userParams
            If oUserParam.name = oCell.Value Then
            oUserParam.Expression = oCell.Offset(0, 1).Value
            End If
        Next
    Next
    MsgBox "Done!"
End Sub

 

Capture2.JPG