hello,
I am trying to change user parameter of assembly & base on that occureence name "GEAR BOX" replace file & active required model state. need help.
Public Sub SetGearandMotor(ByRef TxtGearSize As Windows.Forms.TextBox, ByRef TxtRatio As Windows.Forms.TextBox, ByRef TxtMotorSize As Windows.Forms.TextBox)
Try
Dim TextValue As String = TxtGearSize.Text
Dim TextValue2 As String = TxtMotorSize.Text
Dim TextValue1 As String = TxtRatio.Text
' Get the assembly document
Dim oAssDoc As AssemblyDocument = invApp.ActiveDocument
' Replace the component with the new file
Dim newComponentFilePath As String = "M:\MIXION\LIBRARY\PREFERENCES\GEAR BOX\BONFIGLIOLI MAKE GEAR BOX\"
Dim Filename As String = $"{TextValue} F P{TextValue2} B5 V1.ipt"
Dim newStateName As String = $"{Filename}_RATIO_{TextValue1}"
Dim newFilePathWithState As String = $"{newComponentFilePath}{newStateName}"
' Check if the new file exists
If Not IO.File.Exists(newFilePathWithState) Then
MsgBox($"File '{newFilePathWithState}' not found.")
Exit Sub
End If
' Get the component occurrence by name
Dim selectedComponent As ComponentOccurrence = Nothing
For Each occurrence As ComponentOccurrence In oAssDoc.ComponentDefinition.Occurrences
If occurrence.Name = "GEAR BOX" Then
selectedComponent = occurrence
Exit For
End If
Next
' Check if the component occurrence was found
If selectedComponent Is Nothing Then
MsgBox("Component occurrence 'GEAR BOX' not found.")
Exit Sub
End If
' Replace the component
selectedComponent.Replace(newFilePathWithState, True)
' Activate the new occurrence
Dim newOccurrence As ComponentOccurrence = oAssDoc.ComponentDefinition.Occurrences.ItemByName(newStateName)
If newOccurrence IsNot Nothing Then
newOccurrence.Activate()
Else
MsgBox("New occurrence not found.")
End If
Catch ex As Exception
MsgBox("Error setting gear and motor: " & ex.Message)
End Try
End Sub
Regards,
Dhaval