This blog post is a direct result of a discussion on Twitter! the request was to automatically assign a random colour to a face in an Inventor part.

I wrote a little bit of code, loosely based my previous blog post, looking at generating random numbers to create colours. This specific code simply assigns a random appearance to a face in Inventor, the code keeps running until the user hits “Escape”, the tool-tip explains this to the user.

You can set all of the faces back to default by using the code in this blog post.

The animated GIF below shows the utility in action.

The iLogic code is available below. Make sure to change “RULENAME” below to match the name of your rule, this allows the rule to keep running, until you hit escape.

'Code by @ClintBrown3D, originally posted at https://clintbrown.co.uk/set-random-face-colours-with-ilogic On Error GoTo ClintBrown3D Dim doc = ThisApplication.ActiveDocument Dim entity = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFaceFilter, "Select a Face, ESC to Cancel") RANDOMISER = Round(Rnd * 750) 'RANDOMISER = "Default" oColour = RANDOMISER oStyle = doc.RenderStyles.Item(RANDOMISER) entity.SetRenderStyle(kOverrideRenderStyle, oStyle) iLogicVb.RunRule("RULENAME") Return ClintBrown3D: