
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everyone,
I've been at this for a couple days now trying to figure how code up a material library. I would like to use a spreadsheet to feed a material properties library. What I know so far is that the material, appearance, and physical properties are 3 different assets. So a copper material contains the material asset, an appearance asset, and a physical property asset each with its own values. For now, I am just focusing on the physical asset.
I also know that material asset can not be created or even modified in an asset library, but rather created in the open document and then copied to the asset library. Here is the code I have so far that is able to create a new material and change its physical properties, but I am stuck on how to get it to save to the Asset library after. Any help is appreciated, Thank you for you time.
Sub AddMaterialToLibrary()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oApp As Application
Set oApp = ThisApplication
Dim AssetLib As AssetLibrary
Set AssetLib = ThisApplication.AssetLibraries.Open("C:\Temp\Asset Lib.adsklib")
'Dim myAssetLib As AssetLibrary
'Set myAssetLib = AssetLib("Asset Lib")
' Create new asset
Dim newAsset As Asset
Set newAsset = oDoc.Assets.Add(kAssetTypeMaterial, "Metal", "New Material", "New Material")
Set localPhysicalPropsAsset = newAsset.PhysicalPropertiesAsset
newAsset.PhysicalPropertiesAsset.Item("structural_Density").value = 9000
newAsset.PhysicalPropertiesAsset.Item("structural_Thermal_conductivity").value = 0.15
newAsset.PhysicalPropertiesAsset.Item("structural_Specific_heat").value = 1.5
newAsset.PhysicalPropertiesAsset.Item("structural_Thermal_expansion_coefficient").value = 150
newAsset.PhysicalPropertiesAsset.Item("structural_Young_modulus").value = 2900000
newAsset.PhysicalPropertiesAsset.Item("structural_Poisson_ratio").value = 0.4
newAsset.PhysicalPropertiesAsset.Item("structural_Shear_modulus").value = 6400
newAsset.PhysicalPropertiesAsset.Item("structural_Minimum_yield_stress").value = 6500
newAsset.PhysicalPropertiesAsset.Item("structural_Minimum_tensile_strength").value = 19000
' Apply newly created material to part
'oDoc.ActiveMaterial = localAsset
' Get reference to part material object
Dim oLocalMat As Material
Set oLocalMat = oDoc.ComponentDefinition.Material
'This is a workaround to refresh materials info in the UI.
Call oDoc.BrowserPanes.ActivePane.TopNode.DoSelect
newAsset.CopyTo (AssetLib)
End Sub
Solved! Go to Solution.