Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everyone,
i have a code, adding a material to a (for now) temporary Material Library. It all works fine, but I need to set the Material Category to the new material.
I tried to add a material category but it didn't work with something like this:
AssetLib.MaterialAssetCategories.Add("","")
Has someone a clue or an idea?
'option explicit on
' PROGRAMMABLAUF
Sub Main()
AddMaterialToLibrary
End Sub
Sub AddMaterialToLibrary()
' Konfiguration -----------------------------------------------------------------------------------
Dim stNameMaterialdatenbank As String = "XXX"
' -------------------------------------------------------------------------------------------------
' Vorbedingungen prüfen
If ThisDoc.Document.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then ' prüfen, ob Bauteil
Dim oDoc As PartDocument
oDoc = ThisDoc.Document
Dim oApp As Inventor.Application
oApp = ThisApplication
Dim AssetLib As AssetLibrary
AssetLib = oApp.AssetLibraries.Open("C:\temp_Material\Asset_Lib_abc.adsklib")
oDoc.ActiveMaterial = oApp.AssetLibraries.Item(stNameMaterialdatenbank).MaterialAssets.Item("---")
' Lösche alle lokalen, unbenutzte Materialien
Dim i As Integer
i = 1
While i <= oDoc.MaterialAssets.Count
If oDoc.MaterialAssets.Item(i).IsUsed = False Then
oDoc.MaterialAssets.Item(i).Delete
Else
i = i + 1
End If
End While
' Create new asset
Dim oNewMatAsset As Asset
oNewMatAsset = oDoc.Assets.Add( _ ' Material anlegen
kAssetTypeMaterial, _ ' AssetTypeEnum: kAssetTypeAppearance, kAssetTypeMaterial, kAssetTypePhysicalProperties, kAssetTypeUnknown
"Metall_abc", _ ' Gruppe
"Optional_abc", _ ' Optional
"NeuesMaterial_abc" _ ' Angezeigter Name
)
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Density").value = 9000
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Thermal_conductivity").value = 0.15
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Specific_heat").value = 1.5
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Thermal_expansion_coefficient").value = 150
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Young_modulus").value = 2900000
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Poisson_ratio").value = 0.4
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Shear_modulus").value = 6400
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Minimum_yield_stress").value = 6500
oNewMatAsset.PhysicalPropertiesAsset.Item("structural_Minimum_tensile_strength").value = 19000
' Get reference to part material object
Dim oLocalMat As Material
oLocalMat = oDoc.ComponentDefinition.Material
'This is a workaround to refresh materials info in the UI
Call oDoc.BrowserPanes.ActivePane.TopNode.DoSelect
oNewMatAsset.CopyTo(AssetLib, True)
End If
End Sub
Solved! Go to Solution.