Message 1 of 2
Assigning a material to an assembly for BOM purposes

Not applicable
03-07-2019
11:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
I've been looking high and low on these forums and by googling, but have not found a solution to my issue.
You are my only hope.
I'm trying to assign materials to parts in a assembly, based on the part name.
The materials "Wood" and "Divinycell H60" is already present in the "local" document material assets in the assembly.
When checking the first occurence with "lag" in the part name, Inventor crashes without any given reason at the line:
oc.Definition.Material = asm.Materials.Item("Divinycell H60")
Does anyone have a good solution for me?
Dim doc As Document Set doc = ThisApplication.ActiveDocument If doc.DocumentType = kAssemblyDocumentObject Then 'nothing Else Call MsgBox("Must be an assembly document", vbOKOnly, "Error") Exit Sub End If Dim asm As AssemblyDocument Set asm = ThisApplication.ActiveDocument Dim libasset As MaterialAsset Dim oc As ComponentOccurrence For Each oc In asm.ComponentDefinition.Occurrences If InStr(1, oc.name, "kasse", vbTextCompare) Then oc.Definition.Material = asm.Materials.Item("Wood") End If If InStr(1, oc.name, "skott", vbTextCompare) Then oc.Definition.Material = asm.Materials.Item("Wood") End If If InStr(1, oc.name, "lag", vbTextCompare) Then oc.Definition.Material = asm.Materials.Item("Divinycell H60") End If Next End Sub