Texture Image of Asset
Question:
I have made simple part and assign to one face "Norman - One-Third Running" material from "Autodesk Material Library" . Then I have run VBA sample code "Write out all document appearances API Sample" of API help. The code result does not retrieve texture image. How it can be done ?
Solution:
The texture may be connected to the ColorAssetValue and FloatAssetValue, you can find the two asset values have HasConnectedTexture, but also a texture might also be in the TextureAssetValue. So now there are three asset value object can contain texture info.
- ColorAssetValue
- FloatAssetValue
- TextureAssetValue
In another word, the texture can be in different levels in the asset values, it depends on the type of the asset, like below asset type is Masonry, it has two textures:
Textures are at different locations in different types of asset, however there is not API that tells the type(Note, this is not Asset.AssetType), so we can only iterate all levels of the asset values to get the texture info.
Sub AssetTextureSample() Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument Dim oAppearance As Asset For Each oAppearance In oDoc.AppearanceAssets Dim oColor As ColorAssetValue, oFloat As FloatAssetValue, oTypeTexture As TextureAssetValue Dim oValue As AssetValue If oAppearance.HasTexture Then For Each oValue In oAppearance 'TextureAssetValue If oValue.ValueType = kAssetValueTextureType Then Set oTypeTexture = oValue Dim textureSubValue As AssetValue For Each textureSubValue In oTypeTexture.value Select Case textureSubValue.ValueType Case kAssetValueTypeFilename Dim filenameValue As FilenameAssetValue Set filenameValue = textureSubValue Debug.Print "kAssetValueTextureType " & filenameValue.value End Select Next End If 'ColorAssetValue If oValue.ValueType = kAssetValueTypeColor Then Set oColor = oValue If Not (oColor.ConnectedTexture Is Nothing) Then Debug.Print "---------------------------" Debug.Print oAppearance.DisplayName Dim oTexture As AssetTexture Set oTexture = oColor.ConnectedTexture Dim oTextureValue As AssetValue For Each oTextureValue In oTexture If oTextureValue.ValueType = kAssetValueTypeFilename Then Dim oFilename As FilenameAssetValue Set oFilename = oTextureValue If oFilename.HasMultipleValues Then Dim sFiles() As String sFiles = oFilename.Values Dim i As Long For i = 0 To UBound(sFiles) Debug.Print "kAssetValueTypeColor " & sFiles(i) Next Else Debug.Print "kAssetValueTypeColor " & oFilename.value End If End If Next End If End If ' FloatAssetValue If oValue.ValueType = kAssetValueTypeFloat Then Set oFloat = oValue If Not (oFloat.ConnectedTexture Is Nothing) Then Debug.Print "---------------------------" Debug.Print oAppearance.DisplayName Set oTexture = oFloat.ConnectedTexture For Each oTextureValue In oTexture If oTextureValue.ValueType = kAssetValueTypeFilename Then Set oFilename = oTextureValue If oFilename.HasMultipleValues Then sFiles = oFilename.Values For i = 0 To UBound(sFiles) Debug.Print "kAssetValueTypeFloat " & sFiles(i) Next Else Debug.Print "kAssetValueTypeFloat " & oFilename.value End If End If Next End If End If Next End If Next End Sub