Q: How can I access the rotation and scale data of the texture?
All these values are stored in the appearance asset in the Inventor document. An asset is a collection of values of different types. They can be simple types like floats, integers, strings, and Booleans, but they can also be more complex types like color, filename, reference to other assets, textures, and choices. In this case we need to find texture and access its values.
The following VBA sample prints all values stored in the AssetTexture object from the active Appearance object.
Sub AssetTextureSample()
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oAppearance As Asset
Set oAppearance = oDoc.ActiveAppearance
Dim oValue As AssetValue
For Each oValue In oAppearance
If oValue.ValueType = AssetValueTypeEnum.kAssetValueTextureType Then
Dim oTextureAssetValue As TextureAssetValue
Set oTextureAssetValue = oValue
Dim oTexture As AssetTexture
Set oTexture = oTextureAssetValue.value
If oTexture.Item("unifiedbitmap_Bitmap").value <> "" Then
Debug.Print "---------------------------"
Debug.Print oAppearance.DisplayName
Debug.Print "---------------------------"
Dim v As Variant
For Each v In oTextureAssetValue.value
Debug.Print v.name, v.value
Next
Debug.Print "---------------------------" & vbNewLine
End If
End If 'texture
Next 'AssetValue
Beep
End Sub
Output:
---------------------------
Birch - Natural Polished
---------------------------
AssetLibID AFEFC330-5E61-4E24-814F-AE810148B79D
ExchangeGUID
common_Shared_Asset common_shared
common_Tint_color 50383104
common_Tint_toggle False
texture_LinkTextureTransforms False
texture_MapChannel 1
texture_MapChannel_ID_Advanced 1
texture_MapChannel_UVWSource_Advanced 0
texture_OffsetLock False
texture_RealWorldOffsetX 0
texture_RealWorldOffsetY 0
texture_RealWorldScaleX 10
texture_RealWorldScaleY 10
texture_ScaleLock True
texture_UOffset 0
texture_URepeat True
texture_UScale 1
texture_UVScale 1
texture_VOffset 0
texture_VRepeat True
texture_VScale 1
texture_WAngle 0
unifiedbitmap_Bitmap 1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png
unifiedbitmap_Blur 0,01
unifiedbitmap_Blur_Offset 0
unifiedbitmap_Filtering 0
unifiedbitmap_Invert False
unifiedbitmap_RGBAmount 1
---------------------------
Highlighted members are responsible for the texture rotate angle (texture_Wangle) and scale (texture_RealWorldScaleX and texture_RealWorldScaleY). Adding the lines below to the VBA sample you may get the current angle and scale data in more convenient format:
If oTexture.Item("unifiedbitmap_Bitmap").value <> "" Then
Debug.Print "---------------------------"
Debug.Print oAppearance.DisplayName
Debug.Print "---------------------------"
Debug.Print " unified bitmap path: ", _
oTexture.Item("unifiedbitmap_Bitmap").value
Debug.Print " Rotation angle,deg (texture_WAngle): " _
& oTexture.Item("texture_WAngle").value
Debug.Print " X Size (texture_RealWorldScaleX): " _
& oTexture.Item("texture_RealWorldScaleX").value & " " _
& oTexture.Item("texture_RealWorldScaleX").Units
Debug.Print " Y Size (texture_RealWorldScaleY): " _
& oTexture.Item("texture_RealWorldScaleY").value & " " _
& oTexture.Item("texture_RealWorldScaleY").Units
Debug.Print "---------------------------" & vbNewLine
End If
Output:
---------------------------
Birch - Natural Polished
unified bitmap path: 1/Mats/Woods & Plastics.Finish Carpentry.Wood.Red Birch.png
Rotation angle,deg (texture_WAngle): 30
X Size (texture_RealWorldScaleX): 10 Inch
Y Size (texture_RealWorldScaleY): 10 Inch
---------------------------
Note: Rotation angle is represented in degrees in the range 0° – 360°.
Rotation and scale properties are read and write, so we may change them. Attached part document (Inventor 2016 format) contains the iLogic rule that rotates the active texture according the current value on the slider in the iLogic form:
Here is the iLogic code:
' this iLogic rule rotates the active texture in the range 0° - 360°
' User parameter TextureAngle is controlled by the slider on the iLogic form
DimoDocAsPartDocument = ThisDoc.Document
DimoAppearanceAsAsset = oDoc.ActiveAppearance
DimoValueAsAssetValue
ForEachoValueInoAppearance
IfoValue.ValueType = AssetValueTypeEnum.kAssetValueTextureTypeThen
DimoTextureAssetValueAsTextureAssetValue = oValue
DimoTextureAsAssetTexture = oTextureAssetValue.Value
IfoTexture.Item("unifiedbitmap_Bitmap").Value <> ""Then
oTexture.Item("texture_WAngle").Value = TextureAngle
EndIf
EndIf
Next
Please refer “Materials and Appearances” overview in the Inventor API Help for additional information on this topic.