"Refreshing" iAssembly occurrences after creating new members

"Refreshing" iAssembly occurrences after creating new members

lewis.youngDM9H4
Explorer Explorer
143 Views
1 Reply
Message 1 of 2

"Refreshing" iAssembly occurrences after creating new members

lewis.youngDM9H4
Explorer
Explorer

Hi All,

 

I've been starting to experiment with using iAssemblies & iParts recently and I've come across an annoying limitation.

 

If the iAssemby & iPart tables are updated with new members, when I go into an assembly where I've already got that parent member placed, I have to replace it with itself in order to "refresh" the assembly. From what I've read on here, this is a known and intended limitation.

 

I can do this manually by either component replacing and selecting the same table member, or by expanding the browser node and right clicking the occurrence table to select Change Component. This isn't practical for when I have a large assembly with varying members, as I have to replace each one manually.

 

I'm trying to put together some code that will update each iassembly occurrence with itself instead of doing it manually. I've tried using the standard component.replace which doesn't work. I've tried using Component.ReplaceiPart which I think isn't working because It's an iAssembly. I've tried using iAssembly.ChangeRow to change it to the same row which doesn't work. I've also used the iAssembly.ChangeRow to switch to a different row and then switch back, which works for a brief second while the dummy row is in place, but goes back to being invisible once the original row is selected again. 

 

If anybody has overcome this issue already, i'd really appreciate some help with this 😅

 

Thanks

0 Likes
144 Views
1 Reply
Reply (1)
Message 2 of 2

WCrihfield
Mentor
Mentor

Hi @lewis.youngDM9H4.  I never really got into iAssemblies, but I did use iParts for a while, years ago.  That system did not work very well for us for various reasons.  Anyways, I still understand the basics of those systems.  You can have a row for a member, without there actually being a member model file for that row yet.  Then you can 'generate' the member model file, or 'regenerate' the member model file, if it already existed, but needed to be updated, due to changes in the factory table.  Then those member model files are sort of like read only, slave files, with no modeling history, all saved within a sub folder in the same location as the parent factory file.

 

Have you tried using the 'Rebuild All' tool (on the Manage Tab, Update panel), to see if that would force the old versions of iAssembly members to update to current?

 

The following code will only run on an assembly, and will only process 'top level' components that represent iAssemblyMembers.  That behavior / functionality can be changed though, if needed.  It will simply attempt to replace each component that represents an iAssemblyMember with the same file, and same member name, that it was originally set to, since you said that process was working for you manually.  When it does a replacement, it is set to 'replace all'.  Because of that, it also uses a List(Of String) to keep track of the FullDocumentName that was replaced, so it does not attempt to replace other instances of the same group of occurrences again later.  I have not tested this yet, because I do not use the iAssembly system myself.

 

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
	Dim oFDNs As New List(Of String)
	For Each oOcc As ComponentOccurrence In oOccs
		If Not oOcc.IsiAssemblyMember Then Continue For
		Dim sFDN As String = oOcc.ReferencedDocumentDescriptor.FullDocumentName
		If oFDNs.Contains(sFDN) Then Continue For
		Try
			oOcc.Replace2(sFDN, True)
			oFDNs.Add(sFDN)
		Catch
		End Try
	Next oOcc
	oADoc.Update2(True)
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes