Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Replace components in weldment assembly

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
HSSTW
905 Views, 3 Replies

Replace components in weldment assembly

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

3 REPLIES 3
Message 2 of 4
MSabottoAdskID
in reply to: HSSTW

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.

 

 

Message 3 of 4
adam.nagy
in reply to: HSSTW

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,



Adam Nagy
Autodesk Platform Services
Message 4 of 4
HSSTW
in reply to: HSSTW

Hi Adam,

 

yes it works fine - thanks!!! Smiley Very Happy

 

Now I can complete my function!

 

Cheers,

Stefan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report