Assigning a material to an assembly for BOM purposes

Assigning a material to an assembly for BOM purposes

Anonymous
Not applicable
447 Views
1 Reply
Message 1 of 2

Assigning a material to an assembly for BOM purposes

Anonymous
Not applicable

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
0 Likes
448 Views
1 Reply
Reply (1)
Message 2 of 2

bradeneuropeArthur
Mentor
Mentor

Turn your assembly first into a "weldment assembly".

"Normal Assemblies" don't have material.

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes