API The same orientation of texture on all faces

API The same orientation of texture on all faces

AlexShtol
Participant Participant
654 Views
1 Reply
Message 1 of 2

API The same orientation of texture on all faces

AlexShtol
Participant
Participant

Hello. There is a problem. When extruded, the texture changes direction. I need to have a texture on all faces of the same direction. Later, when I will rottate flat pattern of the sheet material, the direction of the texture should change. Tell me how to implement this.

There is a "TextureMaps" property on the face, and different methods associated with the texture map, but I still have not figured out how to access these properties

question.jpgquestion2.jpg

Thanks,

 

Alex

0 Likes
655 Views
1 Reply
Reply (1)
Message 2 of 2

YuhanZhang
Autodesk
Autodesk

The TextureMaps does not provide the property to change the texture orientation, you can use the appearance asset to change it, below is a VBA sample to do this, you can select a face in UI then run the code:

 

Sub RotateTextureOfAppearanceOnFace()
    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    On Error Resume Next
    ' Select a Face from UI first.
    Dim oFace As Face
    Set oFace = oDoc.SelectSet(1)
    
    If Err Then
        MsgBox "Select a Face from UI first!"
        Exit Sub
    End If
    
    Dim oAppearance As Asset
    Set oAppearance = oFace.Appearance
    
    Dim oNewAppearance As Asset
    Set oNewAppearance = oAppearance.Duplicate
     
    Dim oAssetValue As AssetValue
    Dim oTextureAssetValue As TextureAssetValue
    Dim oRotationValue As FloatAssetValue
    Dim oAssetTexture As AssetTexture
    
    ' find a texture and rotate the texture by 90 degrees.
    For Each oAssetValue In oNewAppearance
        If oAssetValue.ValueType = kAssetValueTextureType Then
            If InStr(1, LCase(oAssetValue.Name), "color") Then
                
                Set oTextureAssetValue = oAssetValue
  
                Set oRotationValue = oTextureAssetValue.Value("texture_WAngle") '(23) / Angle
                
                oRotationValue.Value = 90 ' This should be a defect that the Double value is not in radians.
            End If
         ElseIf oAssetValue.ValueType = kAssetValueTypeColor Then
            
            Dim oColorAssetValue As ColorAssetValue
            Set oColorAssetValue = oAssetValue
            
            If oColorAssetValue.HasConnectedTexture Then
                
                    Set oAssetTexture = oColorAssetValue.ConnectedTexture
                    Set oRotationValue = oAssetTexture.Item("texture_WAngle") '(23) / Angle
                            
                    oRotationValue.Value = 90 ' This should be a defect that the Double value is not in radians.
            End If
        End If
    Next
    
    ' override the appearance
    oFace.Appearance = oNewAppearance
End Sub

 

Hope this helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes