' Start of iLogic rule ======================================================= ' This rule replaces a component in a sub-assembly with an alternative, including ' error checking to ensure the component names are correct. Dim oAsmDoc As AssemblyDocument = Nothing Dim oOcc As ComponentOccurrence = Nothing ' Define the names of the components... Dim SubAssemblyName As String = "SUB-ASM1:1" Dim OriginalCompName As String = "CHANNEL1:1" Dim NewFileName As String = "CHANNEL2.ipt" ' Check we are in an assembly file... Try oAsmDoc = ThisApplication.ActiveEditDocument Catch MsgBox("This rule can only be run from an assembly file - it should be run from top-level assembly", 64, "Cadline iLogic") Return End Try ' Define the sub-assembly we want to replace something in Dim oSubAsmOcc As ComponentOccurrence = Component.InventorComponent(SubAssemblyName) ' Activate it for edit oSubAsmOcc.Edit Try ' Check that the component we want to replace exists... oOcc = Component.InventorComponent(OriginalCompName) Catch MsgBox("There is no component called '" & OriginalCompName & "' in sub assembly '" & SubAssemblyName & "' - Exiting....", 64, "Cadline iLogic") ' Finish editing sub-assembly and return to the top-level oSubAsmOcc.ExitEdit(ExitTypeEnum.kExitToTop) Exit Sub End Try Try ' Replace the desired component with an alternative Component.Replace(OriginalCompName, NewFileName, True) Catch MsgBox("Couldn't find a file called '" & NewFileName & "' in the same folder as the current assembly - Exiting....", 64, "Cadline iLogic") ' Finish editing sub-assembly and return to the top-level oSubAsmOcc.ExitEdit(ExitTypeEnum.kExitToTop) Exit Sub End Try ' Finish editing the sub-assembly and return to the top-level oSubAsmOcc.ExitEdit(ExitTypeEnum.kExitToTop) ' End of iLogic rule =======================================================