Appearance color to specific face

Appearance color to specific face

markGlthen
Enthusiast Enthusiast
995 Views
4 Replies
Message 1 of 5

Appearance color to specific face

markGlthen
Enthusiast
Enthusiast

Hi, 

 

I'm using Inventor 2020 and I would like to know how to apply a color to specific face using iLogic.

Face0 = Red
Face1 = Yellow

 

FaceColor.png

 

I tried to use "iProperties.PartColor", but this paint all faces. 

 

0 Likes
996 Views
4 Replies
  • part
Replies (4)
Message 2 of 5

robertast
Collaborator
Collaborator

Here at me I change the colors depending on the features

Sub main()


Dim partDoc As PartDocument = ThisDoc.Document
Dim namedEntities = iLogicVb.Automation.GetNamedEntities(partDoc)
Dim faceF As Face = namedEntities.FindEntity("Front")
Dim faceB As Face = namedEntities.FindEntity("Back")
Dim faceL As Face = namedEntities.FindEntity("Left")
Dim faceR As Face = namedEntities.FindEntity("Right")

Dim a As String = iProperties.Value("Custom", "Ak1") 
Dim b As String = iProperties.Value("Custom", "Ak2")
Dim c As String = iProperties.Value("Custom", "Pk1")
Dim d As String = iProperties.Value("Custom", "Pk2")

If a = ""
faceF.Appearance = partDoc.AppearanceAssets("_oMDP")
Else
faceF.Appearance = partDoc.AppearanceAssets(iProperties.PartColor)
End If

If b = ""
faceB.Appearance = partDoc.AppearanceAssets("_oMDP")
Else
faceB.Appearance = partDoc.AppearanceAssets(iProperties.PartColor)
End If

If c = ""
faceL.Appearance = partDoc.AppearanceAssets("_oMDP")
Else
faceL.Appearance = partDoc.AppearanceAssets(iProperties.PartColor)
End If

If d = ""
faceR.Appearance = partDoc.AppearanceAssets("_oMDP")
Else
faceR.Appearance = partDoc.AppearanceAssets(iProperties.PartColor)
End If

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()

End Sub
0 Likes
Message 3 of 5

markGlthen
Enthusiast
Enthusiast

@robertastthank you for replying. 

I didn't understand why do you created a custom properties "Ak1, Ak2..." and what would "_oMDP" be?

I just want to color the "Face0" with red color, I tried it, but no worked. 

 

Sub main()

Dim partDoc As PartDocument = ThisDoc.Document
Dim namedEntities = iLogicVb.Automation.GetNamedEntities(partDoc)
Dim faceF As Face = namedEntities.FindEntity("Face0")

Dim a As String = iProperties.Value("Custom", "Red") 

If a = ""
faceF.Appearance = partDoc.AppearanceAssets("Red")
Else
faceF.Appearance = partDoc.AppearanceAssets(iProperties.PartColor)
End If

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()

End Sub

 

0 Likes
Message 4 of 5

FINET_Laurent
Advisor
Advisor

I made up this code with bits from the forum.

It turns the desired face to a random color.

Can't find how to get a specific colors.

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim namedEntities = iLogicVb.Automation.GetNamedEntities(oDoc)
Dim faceA As Face = namedEntities.FindEntity("Face0")

Dim uApprearence As Asset
uApprearence = oDoc.Assets.Add(kAssetTypeAppearance, "Generic", "appearances")
Dim uColor As ColorAssetValue
      
	  uColor = uApprearence.Item("generic_diffuse")
		RNG = Round(Rnd * 255)
		RNG1 = Round(Rnd * 255)
		RNG2 = Round(Rnd * 255)

        uColor.Value = ThisApplication.TransientObjects.CreateColor(RNG, RNG1, RNG2)
        
        faceA.Appearance = uApprearence

Regards,

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 5 of 5

moveworkforward
Contributor
Contributor

Please run this iLogic rule in the part document.

It will set Face1 appearance to "Light Red-Orange" and Face2 to "Smooth - Yellow".

Sub Main
	Dim assetName1 = "Light Red-Orange"
	Dim assetName2 = "Smooth - Yellow"
	
	Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
	Call CopyAssetToLocalDocument(assetName1,oPartDoc)
	Call CopyAssetToLocalDocument(assetName2,oPartDoc)
	oPartDoc.ComponentDefinition.SurfaceBodies(1).Faces(1).Appearance = oPartDoc.AppearanceAssets.Item(assetName1)
	oPartDoc.ComponentDefinition.SurfaceBodies(1).Faces(2).Appearance = oPartDoc.AppearanceAssets.Item(assetName2)
End Sub

Sub CopyAssetToLocalDocument(assetName As String,oPartDoc As PartDocument)
	Dim assetLib As Asset 
	assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library").AppearanceAssets(assetName)
	Dim oAsset As Asset
	Dim AssetIsFound As Boolean: AssetIsFound = False
	For Each oAsset In oPartDoc.AppearanceAssets
	    If oAsset.DisplayName = assetName Then
	        AssetIsFound = True
	        Exit For
	    End If
	Next
	If AssetIsFound = False Then
		oAsset = assetLib.CopyTo(oPartDoc)
	End If
End Sub