Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Need to change file & active model state

dhaval3112
Advocate

Need to change file & active model state

dhaval3112
Advocate
Advocate

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

0 Likes
Reply
127 Views
0 Replies
Replies (0)