Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iParts and iAssemblies are best used to create/update/maintain a background library, when you have a file from that library placed in your top assembly there is code to easily swap between members of the same library: "ThisDoc.Document.ComponentDefinition.Occurrences.ItemByName("Part1:1").ChangeRowOfiAssemblyMember('Specify Row Number as Long or MemberName as String')" ' ChangeRowOfiPartMember works the same way.

 

However, I highly recommend you don't use the code that does that function.  In a fresh Inventor session, when you do what's called a Table Replace, either manually or through code, you'll see that, depending on the size and number of iParts/iAssemblies used to build up your library, it will take Inventor a long time to get that function done.  If you open Task Manager while Inventor is doing this and filter your Processes tab by CPU you'll see one or a few Excel processes in the background.  When any of those tables are accessed in a new Inventor session they will have to be perused for whatever reason, at some point one of my iAssemblies that had several thousand members would take 15 minutes for the first change to happen, however after those tables have been perused it will be faster until you closed Inventor again.  It's not a good method when you want a template that changes ASAP.

 

Therefore my recommendation is to use Component Replace in your code instead:

ThisDoc.Document.ComponentDefinition.Occurrences.ItemByName("Part1:1").Replace("C:\Vault Working Folder\Designs\Assembly Template\Library\Part2.ipt", False)

 

It goes so much faster than Table Replace since it bypasses those background Excel processes, however the only nagging requirement is you have to pre-Generate all table members so the files of your parts and assemblies are in your library along with all the code you'll have to come up with to generate the correct string of text that selects the correct file that you want to replace the Occurrence with.  I guess if you wanted to, you could put both Component Replace in your code with Table Replace as a backup, if the file you're looking for isn't in your library than you could do a Table Replace which will create the file in your library at the same time as the Table Replace function.