Deleting Materials

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have the following code which will eventually be used to replace the materials in an old template with those from a new template.
When I try and run it, I get an error at the line 'OldDocMatls.Item(1).Delete' and an error saying
'Delete method of object material failed'
Can someone please explain why? I have tried several methods to iterate over the materials and delete them but they all come back with this error. There are 23 materials so it is not as if I am trying to delete something that is not actually there!!
Const OldDocLoc As String = "C:\Standard (mm).ipt"
Sub TransferMaterials()
Dim OldDocObj As Inventor.Document
Dim OldDocMatls As Inventor.Materials
'open old document
Set OldDocObj = ThisApplication.Documents.Open(OldDocLoc, False)
'get list of materials in old document
Set OldDocMatls = OldDocObj.Materials
'clean out old materials
Do Until (OldDocMatls.Count = 0)
OldDocMatls.Item(1).Delete
Loop
End Sub
Also whilst I am here, is there a way to copy a collection (ie the material collection) to another without having to iterate through both and replacing each element one by one?
Thanks