Message 1 of 17

Not applicable
02-12-2020
11:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In my assembly I have two parts; Part1.ipt and Part2.ipt, which I have renamed to "MyPart1" and "MyPart2" in the Inventor browser. I want to overwrite MyPart2 with MyPart1, and replace it in the assembly.
My code is:
Dim oOcurrence As ComponentOccurrence = Components("MyPart2").Occurrence Dim PathOfFileToBeReplaced = oOcurrence.Definition.Document.FullFileName oOcurrence.Delete() System.IO.File.Delete(PathOfFileToBeReplaced) Components("MyPart1").Occurrence.Definition.Document.SaveAs(PathOfFileToBeReplaced, True) Components.Add("MyPart2", PathOfFileToBeReplaced)
The first 4 lines run fine, I can see MyPart2 disappearing from the assembly, and Part2.ipt disappears from the folder in Windows Explorer.
But then Document.SaveAs throws an error, just saying "The parameter is incorrect.".
If I save, close, reopen the assembly and run :
Components("MyPart1").Occurrence.Definition.Document.SaveAs("C:\Testing\Part2.ipt", True) Components.Add("MyPart2", "C:\Testing\Part2.ipt")
it works fine! (PathOfFileToBeReplaced = "C:\Testing\Part2.ipt").
Inventor seems to believe that "C:\Testing\Part2.ipt" exists even after the code deletes it, until I reopen the assembly. How do I solve it?
Solved! Go to Solution.