***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:
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.
Solved by W_Barnett. Go to Solution.
Method 1 works as intended. Turns out I needed to restart Inventor.
I did however learn that manually named components in the model browser do not have their names updated when you "Component.Replace" them. Makes things extremely confusing. I couldn't figure out why 4 out of 5 components got replaced correctly, but that one just wouldn't change.
Can't find what you're looking for? Ask the community or share your knowledge.