- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to capture and delete the desired ipt file in an iam file in Inventor. How can I do that ?
Solved! Go to Solution.
I want to capture and delete the desired ipt file in an iam file in Inventor. How can I do that ?
Solved! Go to Solution.
I think you want to delete an occurrence, right?
You can iterate over AssemblyComponentDefinition.Occurrences to find the occurrence you want to delete and then call ComponentOccurrence.Delete method.
Check this post for some code: https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/delete-occurrence-in-assembly/m-p/11...
I tried to capture and delete my file using the code in your answer, but it didn't work. Am I using it correctly?
Before writing code understand what you want achieve and the concept involved. I recommend to name variable properly: `file` is a ComponentOccurrence which is not a file!
Now about your error, check ComponentOccurrences.ItemByName manual, the input param should be the name of an existing occurrence, are you sure filename.ipt is a name of an occurrence? It's possible but sounds weird to me.
var iptFile : assemblyComponentDefinition.Occurrences.ItemByName[$"{iptFileName}:1"];
When I fixed it this way I was able to capture and delete my ipt file. I got a parameter error warning because Inventor adds ":n" to the end of the ipt file in order of addition. Now my problem is solved. Thanks. 😄
Just another approach:
var occ = assemblyComponentDefinition.Occurrences.
Cast<ComponentOccurrence>().
FirstOrDefault(c => c.ReferencedFileDescriptor.FullFileName.Contains(iptFileName));
Jelte de Jong
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.
Blog: hjalte.nl - github.com