Hello Jane Fan,
How to run VBA user parameter of the part component in assembly. Can you hepl me.
I have the code from VBA excel to run into inventor, but not working.
Sub RunIAM()
Dim oWkbk As Workbook
Set oWkbk = ThisWorkbook
Dim oSheet As Worksheet
Set oSheet = oWkbk.ActiveSheet
Dim oInv As Inventor.Application
Set oInv = GetObject(, "Inventor.Application")
Dim oDoc As Document
Set oDoc = oInv.ActiveDocument
Dim oDocAssy As AssemblyDocument
Set oDocAssy = oInv.ActiveDocument
' Define sheet name where information resides
Dim sSheetName As String
sSheetName = "Output Parameter"
' Set range where parameter names reside in sheet
Dim sParamRange As String
sParamRange = "A2:A81"
Dim oCompDef As ComponentDefinition
' Get component definition
Set oCompDef = oDoc.ComponentDefinition
Dim oAsmCompDef As AssemblyComponentDefinition
Set oAsmCompDef = oDocAssy.ComponentDefinition
Dim oOcc As ComponentOccurrence
Set oOcc = oAsmCompDef.Occurrences.Item(1)
'define parameters
Dim oUserParams As UserParameters
Set oUserParams = oCompDef.Parameters.UserParameters
Dim param As Parameter
Dim oCell As Range
' Loop through each parameter listed in sheet
For Each oCell In oSheet.Range(sParamRange)
' Parse through parameters and check to see if parameter name matches current parameter from Excel
For Each oParam In oUserParams
' If names match, copy value and units from Excel into parameter expression
If oCell.Value = oParam.Name Then
oParam.Expression = oCell.Offset(0, 1).Value & oCell.Offset(0, 2).Value
End If
Next oParam
Next oCell
'Suppress feature
If Range("K6").Value = "L" Then
Dim oHole4 As Inventor.PartFeature
Set oHole4 = oAsmCompDef.Occurrences.Item(1).Features("Hole4")
oHole4.Suppressed = True
Dim oHole5 As Inventor.PartFeature
Set oHole5 = oDocPart.ComponentDefinition.Features("Hole5")
oHole5.Suppressed = False
ElseIf Range("K6").Value = "R" Then
Set oHole4 = oAsmCompDef.Occurrences.Item(1).Features("Hole4")
oHole4.Suppressed = False
Set oHole5 = oDocPart.ComponentDefinition.Features("Hole5")
oHole5.Suppressed = True
End If
If Range("K8").Value = "DE" Then
Dim oMirror1 As Inventor.PartFeature
Set oMirror1 = oDocPart.ComponentDefinition.Features("Mirror1")
oMirror1.Suppressed = True
Dim oHole3 As Inventor.PartFeature
Set oHole3 = oDocPart.ComponentDefinition.Features("Hole3")
oHole3.Suppressed = False
ElseIf Range("K8").Value = "NDE" Then
Set oMirror1 = oDocPart.ComponentDefinition.Features("Mirror1")
oMirror1.Suppressed = False
Set oHole3 = oDocPart.ComponentDefinition.Features("Hole3")
oHole3.Suppressed = True
End If
If Range("K4").Value = "D1328" Then
Dim oHole6 As Inventor.PartFeature
Set oHole6 = oDocPart.ComponentDefinition.Features("Hole6")
oHole6.Suppressed = True
Dim oExtrude3 As Inventor.PartFeature
Set oExtrude3 = oDocPart.ComponentDefinition.Features("Extrusion3")
oExtrude3.Suppressed = True
Else
Set oHole6 = oDocPart.ComponentDefinition.Features("Hole6")
oHole6.Suppressed = False
Set oExtrude3 = oDocPart.ComponentDefinition.Features("Extrusion3")
oExtrude3.Suppressed = False
End If
Set oExcel = Nothing
' Update part/assembly
oDoc.Update
ActiveWorkbook.Save
End Sub
Thank you.