- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
***Solved***
1. Manually named components that are replaced will keep their overwritten names. You can check if "Component.Replace" worked correctly by checking iProperties.
2. If a command isn't working as intended, and you know it should, then try restarting Inventor. Would have saved me about 2 hours this morning if I had just restarted and tried running the rule again.
***Original Post***
I've been trying to replace a part file in an assembly using iLogic, however the component is not actually being replaced with anything. I've tried four different methods:
- Target object occurrence (oOcc) and replace (oOcc.Replace...)
- Component Replace using string variables (I want to replace "Comp_A:1" with "P:\...\temp_Comp_A.ipt")
- Component Replace using manually typed strings.
- Component Replace using oOcc.Name and file path.
Nothing is working. I understand that Component.Replace will replace components within the same folder, but I've read several places (including the code snippet) that I can use a target path. Is there a work around? Here's the code in question:
Sub Main() Dim oldPart = "Comp_A:1" Dim newPart = "P:\...\temp_Comp_A.ipt". '*** Demo String for Forum Post. '*** Method 1 Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument oADef = oADoc.ComponentDefinition oOccs = oADef.Occurrences Dim oOcc As Object For Each oComp As ComponentOccurrence In oOccs If oComp.Name = oldPart Then Logger.Debug("oComp is: " & oComp.Name & ". It should be the same as " & oldPart) oOcc = oComp End If Next Logger.Debug("Attempting to replace component now...") oOcc.Replace(newPart, False) '*** Method 2 Component.Replace(oldPart, newPart, False) '*** Method 3 Component.Replace("Comp_A:1", "temp_Comp_A.ipt", False) '*** Method 4 Component.Replace(oOcc.Name, newPart, False) InventorVb.DocumentUpdate() End Sub
Solved! Go to Solution.