Hello vba-User,
in past I replaced components in Assemblies with this sub:
Sub testReplacePartInAss()
Call ReplacePartInAss("W:\INVENTOR\T\Part1.ipt", "W:\INVENTOR\T\Part2.ipt")
End Sub
Sub ReplacePartInAss(sInAssFilename As String, sNewFilename As String)
Dim oApp As Inventor.Application
Set oApp = ThisApplication
Dim oOcc As ComponentOccurrence
Dim oSourceDoc As Document
Dim oAssDoc As AssemblyDocument
Set oAssDoc = oApp.ActiveDocument
For Each oSourceDoc In oAssDoc.ReferencedDocuments
For Each oOcc In oAssDoc.ComponentDefinition.Occurrences
If oOcc.ReferencedDocumentDescriptor.FullDocumentName = sInAssFilename Then
Call oOcc.Replace(sNewFilename, False)
End If
Next
Next
End Sub
But if the assembly is a weldment assembly the line
If oOcc.ReferencedDocumentDescriptor.FullDocumentName = sInAssFilename Then
creates an error '91' that the object is not set.
What has to be changed in this code so that it will work with 'normal' assemblies AND weldment Assemblies too.
Thank for your help,
Stefan
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
Hi,
if I well remember, while traversing a welded assembly you'll find a "strange" occurrence with a name like "_W..." which inside inventor model browser corresponds to the "Welding" node at the top of the browser.
If this is the case you have only to skip this occurrence because it is really not an occurrence.
Hi Stefan,
I think you could do something like this:
Sub AvoidWeldmentSpecificOccurrences() Dim doc As AssemblyDocument Set doc = ThisApplication.ActiveDocument Dim occ As ComponentOccurrence For Each occ In doc.ComponentDefinition.Occurrences If occ.Suppressed Then ' A weldment specific occurence cannot be ' suppressed I think, so this one is not a ' weldment specific occurrence ' Also a suppressed component has no Definition ' because the document is not loaded, so occ.Definition ' would throw an error here Else ' Here we can check the Definition If occ.Definition.Type = kWeldsComponentDefinitionObject Then ' This is a weldment specific occurrence ' so just ignore it End If End If Next End Sub
I hope this helps.
Cheers,