01-23-2020
08:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
01-23-2020
08:41 AM
Hi @Anonymous
Here is an attached Inventor 2020 file as an example:
https://forums.autodesk.com/autodesk/attachments/autodesk/78/775245/1/Cube%20Color%20Face.ipt
Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Here's the code (for future searches) and a couple of screen shots concerning the face naming steps, in case those help someone else in the future as well.
'set this rule to watch these parameters
oTrigger = FaceIsColored
oTrigger = FaceColor
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
'create list of colors
Dim oList As New ArrayList
Dim oStyle As RenderStyle
For Each oStyle In oDoc.RenderStyles
oList.Add(oStyle.Name)
Next
MultiValue.List("FaceColor") = oList
'get color name to use
Dim oColor As String
oColor = Parameter("FaceColor")
Dim oAssetLib As AssetLibrary
oAssetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
' Get an asset in the library
Dim oLibAsset As Asset
oLibAsset = oAssetLib.AppearanceAssets.Item(oColor)
Dim oLocalAsset As Asset
Try 'Copy the asset locally.
oLocalAsset = oLibAsset.CopyTo(oDoc)
Catch 'or just use it if it's already local
oLocalAsset = oDoc.Assets.Item(oColor)
End Try
Dim oEntities As Object
oEntities = iLogicVb.Automation.GetNamedEntities(oDoc)
'get the named face
Dim oFace As Face
oFace = oEntities.FindEntity("Target Face")
'set the color if paramter is true
If Parameter("FaceIsColored") = True Then
oFace.Appearance = oLocalAsset
Else
oFace.Appearance = oDoc.ActiveAppearance
End If