Vb.Net "AddIn" dll - AssetLibrary & Material Asset Problem

Vb.Net "AddIn" dll - AssetLibrary & Material Asset Problem

isocam
Collaborator Collaborator
200 Views
2 Replies
Message 1 of 3

Vb.Net "AddIn" dll - AssetLibrary & Material Asset Problem

isocam
Collaborator
Collaborator

Can anybody help?

 

I have the following code that is part of a Vb.Net "AddIn" dll.  

 

The code is taken from the sub: Private Sub ApplicationEvents_OnSaveDocument(.................)


If BeforeOrAfter = EventTimingEnum.kBefore Then
Dim oDoc As Inventor.Document = TryCast(DocumentObject, Inventor.Document)

If oDoc IsNot Nothing And oDoc.DocumentType.Equals(DocumentTypeEnum.kPartDocumentObject) Then
PartMaterial = "Brass, Soft Yellow"

Dim partDoc As PartDocument = oDoc

Dim AssetLib As AssetLibrary = InventorApplication.AssetLibraries.Item(MaterialLibrary)

Dim oMaterial As MaterialAsset

oMaterial = AssetLib.MaterialAssets.Item(PartMaterial)

MsgBox("MATERIAL CURRENTLY SET TO: " + partDoc.ComponentDefinition.Material.Name)

partDoc.ActiveMaterial = oMaterial

MsgBox("MATERIAL UPDATED TO: " + partDoc.ComponentDefinition.Material.Name)
End If
End If

 

I have a problem with the lines highlighted in blue.

 

Does anybody know what is wrong?

 

Many thanks in advance

 

Darren

0 Likes
201 Views
2 Replies
Replies (2)
Message 2 of 3

bradeneuropeArthur
Mentor
Mentor

Change to this and it will work:

 

Dim AssetLib As AssetLibrary = InventorApplication.AssetLibraries.Item(ThisApplication.ActiveMaterialLibrary.DisplayName)

 

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
Message 3 of 3

Curtis_Waguespack
Consultant
Consultant

@isocam, I think  what bradeneuropeArthur said is close, you might just need to change the application reference as shown:

 

InventorApplication.AssetLibraries.Item(InventorApplication.ActiveMaterialLibrary.DisplayName)

 

Hope that helps,

Curtis

 

Curtis_Waguespack_0-1732548972334.png

 

 

 

        Private Sub Events_OnSaveDocument(DocumentObject As _Document,
                      BeforeOrAfter As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)

            If Not DocumentObject Is InventorApplication.ActiveDocument Then Exit Sub 'only trigger on the active file
            If DocumentObject.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
                If BeforeOrAfter = EventTimingEnum.kBefore Then

                    Call SetMaterial(DocumentObject)

                End If
            End If

        End Sub

        Sub SetMaterial(DocumentObject As _Document)

            Dim AssetLib As AssetLibrary = InventorApplication.AssetLibraries.Item(InventorApplication.ActiveMaterialLibrary.DisplayName)
            Dim PartMaterial = "Brass, Soft Yellow"
            Dim oMaterial As MaterialAsset
            oMaterial = AssetLib.MaterialAssets.Item(PartMaterial)

            MsgBox("MATERIAL CURRENTLY SET TO: " + DocumentObject.ComponentDefinition.Material.Name)
            DocumentObject.ActiveMaterial = oMaterial
            MsgBox("MATERIAL UPDATED TO: " + DocumentObject.ComponentDefinition.Material.Name)

        End Sub

 

 

 

EESignature