Hi all,
When i do a replace function with ilogic to change parts in several sub assemblies ilogic skips one assembly.
The first 3 assemblies work fine, only the 4th one is skipped.
when the code is run a second time the last assembly is modified.
Has this something to do with the capabilities of inventor?
for each replace inside a subassembly the code is copied, so i don't think this should be an error in inventor or ilogic.
I build in a counter so the code is run twice in one go, and then it works, but this shoudl be possible to do in one go i think.
Dim Ploc41 As String = ThisDoc.Path Dim oDoc41 As Document = ThisApplication.Documents.ItemByName(Ploc41 & "\4000-5050.iam") Dim oComps41 As ComponentOccurrences = oDoc41.ComponentDefinition.Occurrences For Each oComp41 As ComponentOccurrence In oComps41 If oComp41.Name.Contains("03-02516") Then Component.Replace(oComp41.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\03-Piping\02-Elbow 90°\03-02516" & DN_Header & ".ipt", True) Else If oComp41.Name.Contains("02-11540") Then Component.Replace(oComp41.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\02-Flanges\11-Weld-neck\02-11540" & DN_Header & ".ipt", True) End If Next Dim Ploc42 As String = ThisDoc.Path Dim oDoc42 As Document = ThisApplication.Documents.ItemByName(Ploc42 & "\4000-5000.iam") Dim oComps42 As ComponentOccurrences = oDoc42.ComponentDefinition.Occurrences For Each oComp42 As ComponentOccurrence In oComps42 If oComp42.Name.Contains("03-02516") Then Component.Replace(oComp42.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\03-Piping\02-Elbow 90°\03-02516" & DN_Header & ".ipt", True) Else If oComp42.Name.Contains("02-11540") Then Component.Replace(oComp42.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\02-Flanges\11-Weld-neck\02-11540" & DN_Header & ".ipt", True) End If Next Dim Ploc43 As String = ThisDoc.Path Dim oDoc43 As Document = ThisApplication.Documents.ItemByName(Ploc43 & "\4000-5010.iam") Dim oComps43 As ComponentOccurrences = oDoc43.ComponentDefinition.Occurrences For Each oComp43 As ComponentOccurrence In oComps43 If oComp43.Name.Contains("03-02516") Then Component.Replace(oComp43.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\03-Piping\02-Elbow 90°\03-02516" & DN_Header & ".ipt", True) Else If oComp43.Name.Contains("03-03516") Then Component.Replace(oComp43.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\03-Piping\03-Elbow 45°\03-03516" & DN_Header & ".ipt", True) Else If oComp43.Name.Contains("02-11540") Then Component.Replace(oComp43.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\02-Flanges\11-Weld-neck\02-11540" & DN_Header & ".ipt", True) End If Next Dim Ploc44 As String = ThisDoc.Path Dim oDoc44 As Document = ThisApplication.Documents.ItemByName(Ploc44 & "\4000-5060.iam") Dim oComps44 As ComponentOccurrences = oDoc44.ComponentDefinition.Occurrences For Each oComp44 As ComponentOccurrence In oComps44 If oComp44.Name.Contains("03-02516") Then Component.Replace(oComp44.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\03-Piping\02-Elbow 90°\03-02516" & DN_Header & ".ipt", True) Else If oComp44.Name.Contains("02-11540") Then Component.Replace(oComp44.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\02-Flanges\11-Weld-neck\02-11540" & DN_Header & ".ipt", True) End If Next iLogicVb.UpdateWhenDone = True
kind regards,
Geert
Solved! Go to Solution.
@Anonymous,
Can you please provide non confidential model data to test the behavior?
Thanks and regards,
unfortunatly not, it would take a lot of time to strip the assembly down to only the problem subs.
i found the solution.
It appeared that i first needed to loop trough all the occurences in the main assembly to find the sub i wanted to change parts in.
It was the order in which it found the subs that was wrong, so it would not update a sub when the rule had past the code where it needed to change parts.
Kind regards,
Geert van der Heide
Dim oDoc As AssemblyDocument = ThisDoc.Document Dim oComps As ComponentOccurrences = oDoc.ComponentDefinition.Occurrences Dim Ploc1 As String = ThisDoc.Path For Each oComp As ComponentOccurrence In oComps If oComp.Name.Contains("4000-5050") Then Dim oComps1 As ComponentOccurrences = ThisApplication.Documents.ItemByName(Ploc1 & "\4000-5050.iam").ComponentDefinition.Occurrences For Each oComp1 As ComponentOccurrence In oComps1 If oComp1.Name.Contains("03-02516") Then Component.Replace(oComp1.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\03-Piping\02-Elbow 90°\03-02516" & DN_Header & ".ipt", True) Else If oComp1.Name.Contains("02-11540") Then Component.Replace(oComp1.Name, "C:\Workspace\Documents\Libraries\DMT-Library\New EU\02-Flanges\11-Weld-neck\02-11540" & DN_Header & ".ipt", True) End If Next
Can't find what you're looking for? Ask the community or share your knowledge.