Public Sub DumpDocumentMaterials()
' Check that a part or assembly document is active.
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject And ThisApplication.ActiveDocumentType <> kPartDocumentObject Then
MsgBox "A part or assembly must be active."
Exit Sub
End If
Dim doc As Document
Set doc = ThisApplication.ActiveDocument
' Open a file to write the results.
Open "C:\Temp\DocumentMaterialDump.txt" For Output As #1
Print #1, "Materials in " & doc.FullFileName
' Iterate through the libraries.
Dim material As MaterialAsset
For Each material In doc.MaterialAssets
Print #1, " Material"
Print #1, " DisplayName: " & material.DisplayName
Print #1, " Category: " & material.CategoryName
Print #1, " Associated Appearance: " & material.AppearanceAsset.DisplayName
Print #1, " Associated Physical Properties: " & material.PhysicalPropertiesAsset.DisplayName
Print #1, " IsReadOnly: " & material.IsReadOnly
Print #1, " Name: " & material.Name
Dim value As AssetValue
For Each value In material
Call PrintAssetValue(value, 8)
Next
Next
Close #1
MsgBox "Finished writing output to ""C:\Temp\DocumentMaterialDump.txt"""
End Sub
' Utility function that prints out information for the input asset value.
Private Sub PrintAssetValue(InValue As AssetValue, Indent As Integer)
Dim indentChars As String
indentChars = Space(Indent)
Print #1, indentChars & "Value"
Print #1, indentChars & " DisplayName: " & InValue.DisplayName
Print #1, indentChars & " Name: " & InValue.Name
Print #1, indentChars & " IsReadOnly: " & InValue.IsReadOnly
Select Case InValue.ValueType
Case kAssetValueTextureType
Print #1, indentChars & " Type: Texture"
Dim textureValue As TextureAssetValue
Set textureValue = InValue
Dim texture As AssetTexture
Set texture = textureValue.value
Select Case texture.TextureType
Case kTextureTypeBitmap
Print #1, indentChars & " TextureType: kTextureTypeBitmap"
Case kTextureTypeChecker
Print #1, indentChars & " TextureType: kTextureTypeChecker"
Case kTextureTypeGradient
Print #1, indentChars & " TextureType: kTextureTypeGradient"
Case kTextureTypeMarble
Print #1, indentChars & " TextureType: kTextureTypeMarble"
Case kTextureTypeNoise
Print #1, indentChars & " TextureType: kTextureTypeNoise"
Case kTextureTypeSpeckle
Print #1, indentChars & " TextureType: kTextureTypeSpeckle"
Case kTextureTypeTile
Print #1, indentChars & " TextureType: kTextureTypeTile"
Case kTextureTypeUnknown
Print #1, indentChars & " TextureType: kTextureTypeUnknown"
Case kTextureTypeWave
Print #1, indentChars & " TextureType: kTextureTypeWave"
Case kTextureTypeWood
Print #1, indentChars & " TextureType: kTextureTypeWood"
Case Else
Print #1, indentChars & " TextureType: Unexpected type returned"
End Select
Print #1, indentChars & " Values"
Dim textureSubValue As AssetValue
For Each textureSubValue In texture
Call PrintAssetValue(textureSubValue, Indent + 4)
Next
Case kAssetValueTypeBoolean
Print #1, indentChars & " Type: Boolean"
Dim booleanValue As BooleanAssetValue
Set booleanValue = InValue
Print #1, indentChars & " Value: " & booleanValue.value
Case kAssetValueTypeChoice
Print #1, indentChars & " Type: Choice"
Dim choiceValue As ChoiceAssetValue
Set choiceValue = InValue
Print #1, indentChars & " Value: " & choiceValue.value
Dim names() As String
Dim choices() As String
Call choiceValue.GetChoices(names, choices)
Print #1, indentChars & " Choices:"
Dim i As Integer
For i = 0 To UBound(names)
Print #1, indentChars & " " & names(i) & ", " & choices(i)
Next
Case kAssetValueTypeColor
Print #1, indentChars & " Type: Color"
Dim colorValue As ColorAssetValue
Set colorValue = InValue
Print #1, indentChars & " HasConnectedTexture: " & colorValue.HasConnectedTexture
Print #1, indentChars & " HasMultipleValues: " & colorValue.HasMultipleValues
If Not colorValue.HasMultipleValues Then
Print #1, indentChars & " Color: " & ColorString(colorValue.value)
Else
Print #1, indentChars & " Colors"
Dim colors() As color
colors = colorValue.Values
For i = 0 To UBound(colors)
Print #1, indentChars & " Color: " & ColorString(colors(i))
Next
End If
Case kAssetValueTypeFilename
Print #1, indentChars & " Type: Filename"
Dim filenameValue As FilenameAssetValue
Set filenameValue = InValue
Print #1, indentChars & " Value: " & filenameValue.value
Case kAssetValueTypeFloat
Print #1, indentChars & " Type: Float"
Dim floatValue As FloatAssetValue
Set floatValue = InValue
Print #1, indentChars & " Value: " & floatValue.value
Case kAssetValueTypeInteger
Print #1, indentChars & " Type: Integer"
Dim integerValue As IntegerAssetValue
Set integerValue = InValue
Print #1, indentChars & " Value: " & integerValue.value
Case kAssetValueTypeReference
' This value type is not currently used in any of the assets.
Print #1, indentChars & " Type: Reference"
Dim refType As ReferenceAssetValue
Set refType = InValue
Case kAssetValueTypeString
Print #1, indentChars & " Type: String"
Dim stringValue As StringAssetValue
Set stringValue = InValue
Print #1, indentChars & " Value: """ & stringValue.value & """"
End Select
End Sub
' Utility function that returns a string with the R,G,B,K values for an input Color object.
Private Function ColorString(InColor As color) As String
ColorString = InColor.Red & "," & InColor.Green & "," & InColor.Blue & "," & InColor.Opacity
End Function
Imports System.IO
Class Test
Dim oWriter As System.IO.StreamWriter
Sub Main
' Check that a part or assembly document is active.
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject And ThisApplication.ActiveDocumentType <> kPartDocumentObject Then
MsgBox("A part or assembly must be active.")
Exit Sub
End If
Dim doc As Document
doc = ThisApplication.ActiveDocument
' Open a file to write the results.
oWriter = New StreamWriter("C:\Temp\DocumentMaterialDump.txt")
oWriter.WriteLine("Materials in " & doc.FullFileName)
' Iterate through the libraries.
Dim material As MaterialAsset
For Each material In doc.MaterialAssets
oWriter.WriteLine(" Material")
oWriter.WriteLine(" DisplayName: " & material.DisplayName)
oWriter.WriteLine(" Category: " & material.CategoryName)
oWriter.WriteLine(" Associated Appearance: " & material.AppearanceAsset.DisplayName)
oWriter.WriteLine(" Associated Physical Properties: " & material.PhysicalPropertiesAsset.DisplayName)
oWriter.WriteLine(" IsReadOnly: " & material.IsReadOnly)
oWriter.WriteLine(" Name: " & material.Name)
Dim value As AssetValue
For Each value In material
Call PrintAssetValue(value, 8)
Next
Next
oWriter.Close()
MsgBox("Finished writing output to ""C:\Temp\DocumentMaterialDump.txt""")
End Sub
' Utility function that prints out information for the input asset value.
Private Sub PrintAssetValue(InValue As AssetValue, Indent As Integer)
Dim indentChars As String
indentChars = Space(Indent)
oWriter.WriteLine(indentChars & "Value")
oWriter.WriteLine(indentChars & " DisplayName: " & InValue.DisplayName)
oWriter.WriteLine(indentChars & " Name: " & InValue.Name)
oWriter.WriteLine(indentChars & " IsReadOnly: " & InValue.IsReadOnly)
Select Case InValue.ValueType
Case kAssetValueTextureType
oWriter.WriteLine(indentChars & " Type: Texture")
Dim textureValue As TextureAssetValue
textureValue = InValue
Dim texture As AssetTexture
texture = textureValue.Value
Select Case texture.TextureType
Case kTextureTypeBitmap
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeBitmap")
Case kTextureTypeChecker
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeChecker")
Case kTextureTypeGradient
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeGradient")
Case kTextureTypeMarble
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeMarble")
Case kTextureTypeNoise
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeNoise")
Case kTextureTypeSpeckle
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeSpeckle")
Case kTextureTypeTile
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeTile")
Case kTextureTypeUnknown
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeUnknown")
Case kTextureTypeWave
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeWave")
Case kTextureTypeWood
oWriter.WriteLine(indentChars & " TextureType: kTextureTypeWood")
Case Else
oWriter.WriteLine(indentChars & " TextureType: Unexpected type returned")
End Select
oWriter.WriteLine(indentChars & " Values")
Dim textureSubValue As AssetValue
For Each textureSubValue In texture
Call PrintAssetValue(textureSubValue, Indent + 4)
Next
Case kAssetValueTypeBoolean
oWriter.WriteLine(indentChars & " Type: Boolean")
Dim booleanValue As BooleanAssetValue
booleanValue = InValue
oWriter.WriteLine(indentChars & " Value: " & booleanValue.Value)
Case kAssetValueTypeChoice
oWriter.WriteLine(indentChars & " Type: Choice")
Dim choiceValue As ChoiceAssetValue
choiceValue = InValue
oWriter.WriteLine(indentChars & " Value: " & choiceValue.Value)
Dim names() As String = New String() {}
Dim choices() As String = New String() {}
Call choiceValue.GetChoices(names, choices)
oWriter.WriteLine(indentChars & " Choices:")
Dim i As Integer
For i = 0 To UBound(names)
oWriter.WriteLine(indentChars & " " & names(i) & ", " & choices(i))
Next
Case kAssetValueTypeColor
oWriter.WriteLine(indentChars & " Type: Color")
Dim colorValue As ColorAssetValue
colorValue = InValue
oWriter.WriteLine(indentChars & " HasConnectedTexture: " & colorValue.HasConnectedTexture)
oWriter.WriteLine(indentChars & " HasMultipleValues: " & colorValue.HasMultipleValues)
If Not colorValue.HasMultipleValues Then
oWriter.WriteLine(indentChars & " Color: " & ColorString(colorValue.Value))
Else
oWriter.WriteLine(indentChars & " Colors")
Dim colors() As Color
colors = colorValue.Values
For i = 0 To UBound(colors)
oWriter.WriteLine(indentChars & " Color: " & ColorString(colors(i)))
Next
End If
Case kAssetValueTypeFilename
oWriter.WriteLine(indentChars & " Type: Filename")
Dim filenameValue As FilenameAssetValue
filenameValue = InValue
oWriter.WriteLine(indentChars & " Value: " & filenameValue.Value)
Case kAssetValueTypeFloat
oWriter.WriteLine(indentChars & " Type: Float")
Dim floatValue As FloatAssetValue
floatValue = InValue
oWriter.WriteLine(indentChars & " Value: " & floatValue.Value)
Case kAssetValueTypeInteger
oWriter.WriteLine(indentChars & " Type: Integer")
Dim integerValue As IntegerAssetValue
integerValue = InValue
oWriter.WriteLine(indentChars & " Value: " & integerValue.Value)
Case kAssetValueTypeReference
' This value type is not currently used in any of the assets.
oWriter.WriteLine(indentChars & " Type: Reference")
Dim refType As ReferenceAssetValue
refType = InValue
Case kAssetValueTypeString
oWriter.WriteLine(indentChars & " Type: String")
Dim stringValue As StringAssetValue
stringValue = InValue
oWriter.WriteLine(indentChars & " Value: """ & stringValue.Value & """")
End Select
End Sub
' Utility function that returns a string with the R,G,B,K values for an input Color object.
Private Function ColorString(InColor As Color) As String
ColorString = InColor.Red & "," & InColor.Green & "," & InColor.Blue & "," & InColor.Opacity
End Function
End Class