Save & Replace as Assembly components

Save & Replace as Assembly components

NachoShaw
Advisor Advisor
406 Views
2 Replies
Message 1 of 3

Save & Replace as Assembly components

NachoShaw
Advisor
Advisor

Hey

 

I have a need to save & replace every sub assembly / part in my top level assembly and im coming up with some difficulties. First, a summary.

 

All of the Assembly components are from an imported file. I am not saving the assembly file as i dont need it. I am importing it, processing the names of the components inside the assembly then i need to save & replace each component out as a new name with the last one being the top level assembly.

 

What is the best approach? I am using Active EditDocument whenever i come to a sub assembly so that i can process the sub parts but it doesnt seem to be working for me.. I am using the DocumentDescriptor.ReplaceReference

 

My objective is to have a saved assembly of the exact same structure but with all components having a new name

 

 

Thanks

Thanks

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
407 Views
2 Replies
Replies (2)
Message 2 of 3

yan.gauthier
Advocate
Advocate

I just did the same kind of macro in order to rename imported standard assemblies (e.g.: Festo cylinder) to a standard format for our file standards. In order to replace reference in sub assemblies, you might need to enter each of them in edit mode. 

 

From one assembly, I copy, rename and then replace using this method :

 

oDoc.SaveAs savePath & ComponentName & ".iam", False

'redo reference of all sub components
For Each refDoc In oDoc.AllReferencedDocuments

    If TypeOf refDoc Is PartDocument Then
        fileExtension = ".ipt"
    ElseIf TypeOf refDoc Is AssemblyDocument Then
        fileExtension = ".iam"
    End If
    'increment part suffix (e.g.: XXXXX_1, XXXXX_2, etc...)
    count = count + 1
    
    newFullFileName = savePath & ComponentName & "_" & count & fileExtension
    
    'if file already exists, make a new one based on the first
    If refDoc.FileSaveCounter > 0 Then
        'copy file once, reuse then
        If Not fso.fileExists(newFullFileName) Then
            fso.CopyFile refDoc.Fullfilename, newFullFileName, False '.CopyFile(Source, Dest [,Overwrite (True/False)]
        End If
        Set DocDescriptor = oDoc.ReferencedDocumentDescriptors.item(refDoc.Fullfilename)
        DocDescriptor.ReferencedFileDescriptor.ReplaceReference newFullFileName
    Else
        'Change file name to desired location
        refDoc.Fullfilename = newFullFileName
    End If
    
    'Change document display name
    refDoc.DisplayName = ComponentName & "_" & count
Next refDoc

odoc.update2 true
0 Likes
Message 3 of 3

yan.gauthier
Advocate
Advocate

Also keep in mind that replaceReference works only if part share the same internal name (i.e.: they are a copy of one another)

0 Likes