Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need to change file & active model state

0 REPLIES 0
Reply
Message 1 of 1
dhaval3112
83 Views, 0 Replies

Need to change file & active model state

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 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report