Copy assembly to new location & replace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey
Im copying an assembly from a stored location to a job location and attempting to replace the occurrences within the top level assembly but after much trial and error, i must admit defeat and accept that im going to need some additional help 🙂
im working in VBA (unfortunately, a legacy project)
I am copying the assembly over using FileSystemObject mainly because its super fast. I loop through the documents enumerator to get the full file path add add that to a list. Then i loop the list and copy each file to the new location with the new name.
I close the template and open the new copy in the new location. At this stage, all occurrences are looking at the originals which are what i need to change to the newly created ones.
There arent any resolve issues in the new assembly
Here is my ReplaceComponent sub
Sub ReplaceAllComponents(oComps As ComponentOccurrences, ByVal NewPath As String, ByVal prefix As String)
Dim FSO As Object: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim oComp As ComponentOccurrence
For Each oComp In oComps
Stop
Dim oDoc As Document: Set oDoc = oComp.Definition.Document
Dim oldFileName As String: oldFileName = FSO.GetFileName(oDoc.FullFileName)
Dim NewFileName As String: NewFileName = prefix & oldFileName
Dim NewFilePath As String: NewFilePath = NewPath & NewFileName
Call oComp.Replace(NewFilePath, False)
If oComp.SubOccurrences.Count > 0 Then
Call ReplaceAllComponents(oComp.SubOccurrences, NewPath, prefix)
End If
Next
End Sub
i can replace the first component which is a part then on the second component (an assembly), i get this error
When i try to replace the component manually, i cant do it either. I cant see why i couldnt replace the component as the new version is a copy of the original and the sub components still look at the original components.
What is the error and how can i get around it?
Is there another / better way to change the components?
Thanks
Nacho
Automation & Design Engineer
Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC
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.