Auto update Image Texture of an appearance along the lenght of a face in part

Auto update Image Texture of an appearance along the lenght of a face in part

Anonymous
Not applicable
436 Views
3 Replies
Message 1 of 4

Auto update Image Texture of an appearance along the lenght of a face in part

Anonymous
Not applicable

Hello Everyone,

 

I would like to change the image texture of an appearance that always along the length of a face in a part. Please lead me on how to do that! I am thinking about comparing which direction is the length, then change the rotation of that image but don't know enough API to do.

 

2020-06-08_16h11_52.png

 

Many thanks

0 Likes
437 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

getting the picture to turn to the length of a face seems very difficult to me. because there are some unknown variables. like how is the picture turned to start with in the image (are the lines horizontal or vertical) and is the picture on the face. i think there are to many unknowns.

But a human viewer can see what angle the picture should turn in a instance probably. there for i wrote an iLogic rule that will ask what angle to turn and do it directly. At least it will be a starting point for creating the rule you want. 😉

Dim doc As PartDocument = ThisDoc.Document
For Each asset As Asset In doc.AppearanceAssets
	If (Asset.IsUsed And Asset.HasTexture) Then
		Dim assetValue As TextureAssetValue = Nothing

		For Each item As assetValue In Asset

			If (item.Type.ToString() = "kTextureAssetValueObject" And item.Name.Contains("color")) Then
				assetValue = item
			End If
		Next

		Dim floatAssetValue As FloatAssetValue = Nothing
		For Each item As assetValue In assetValue.Value

			If (item.Type.ToString() = "kFloatAssetValueObject" And item.Name.Contains("WAngle")) Then
				floatAssetValue = item
			End If
		Next
		
		Dim f As Double = Double.Parse(InputBox("What angle to turn?", "Turn angle", "90"))
		floatAssetValue.Value = f

	End If
Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hello Sir,

 

Thanks for your suggestion.

 

Yes, it's really helpful but if we have too many models, we have to spend time a lot. I would like to find the rule like the x or y-axis for the picture!!!

0 Likes
Message 4 of 4

BrandonBG
Collaborator
Collaborator

I haven't figured out how to automate this process, but I do have a rule that allows the user to pick the faces that need to be rotated 90 degrees. This runs at the assembly level.

 

Sub Main()
'Assumes appearances are added at part level'
Dim oAssembly as AssemblyDocument 'run from assembly level with no component edit'
oAssembly = ThisApplication.ActiveDocument

Dim oFaceProxy As FaceProxy 
Dim oFace as Face

Try

While True

oFaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select faces to rotate appearance 90 degrees. ESC to end.")
oFace = oFaceProxy.NativeObject

If IsNothing(oFace) Then Exit While

Dim oAppearance As Asset 
oAppearance = oFace.Appearance

Dim oComponentAsset As Asset
Dim oRotatedAppearance As Asset

Dim sAngle As String
sAngle = " (90)" 'used to name the rotated appearance'

Dim oFoundRotatedAppearance As Boolean
oFoundRotatedAppearance = False

If Instr(oAppearance.DisplayName, sAngle) <> 0 Then 'finds if the appearance is the rotated appearance
	Dim sTrimmedName As String
	sTrimmedName = Left(oAppearance.DisplayName, Instr(oAppearance.DisplayName, sAngle) - 1)
	oRotatedAppearance = oFaceProxy.ContainingOccurrence.Definition.Document.Assets.Item(sTrimmedName)
	
Else  'assumes that the appearance is the original, not rotated'
	For Each oComponentAsset In oFaceProxy.ContainingOccurrence.Definition.Document.Assets
		If oComponentAsset.DisplayName = oAppearance.DisplayName + sAngle Then
			oFoundRotatedAppearance = True
			oRotatedAppearance = oComponentAsset
		Else End If
	Next	

	If oFoundRotatedAppearance = False Then 'create new appearance if not already there

		Dim oNewAppearance As Asset
		oNewAppearance = oAppearance.Duplicate()
		
		Dim oAssetValue as AssetValue 
		Dim oTextureAssetValue as TextureAssetValue 
		Dim oAssetTexture As AssetTexture
		Dim oRotationAngle As Double
		
		For Each oAssetValue In oNewAppearance
			If oAssetValue.ValueType = kAssetValueTypeColor Then
				If oAssetValue.HasConnectedTexture = True Then
					oAssetTexture = oAssetValue.ConnectedTexture
					oRotationAngle = oAssetTexture.Item("texture_WAngle").Value
					If oRotationAngle <> 0 Then
						oRotationAngle = 0
					Else 
						oRotationAngle = 90
					End If
					oAssetTexture.Item("texture_WAngle").Value = oRotationAngle
				Else End If
			Else End If
		Next

		oNewAppearance.DisplayName = oAppearance.DisplayName + sAngle 'rename the new appearance
		oRotatedAppearance = oNewAppearance
	Else End If
End If 

oFace.Appearance = oRotatedAppearance

End While

Catch
End Try

End Sub

Brandon

0 Likes