Hi @Anonymous,
The first link that Cadmanto provided works by changing the color of the feature, where one feature = one solid. That might or might not work for you.
But if you want to grab the solid body rather than the feature it gets a bit more involved. Attached is an example 2017 file that has some example rules that you can look at to see this in action.
And I'll add the code here as well in case you're using a version of Inventor older than 2017.
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
change each body to a different color
Dim oDoc As PartDocument = ThisDoc.Document
oDef = oDoc.ComponentDefinition
'define appearance library by name
Dim assetLib As AssetLibrary
assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
sColor1 = "Red"
sColor2 = "Cyan"
'define colors to work with
Dim libAsset1 As Asset
libAsset1 = assetLib.AppearanceAssets.Item(sColor1)
Dim libAsset2 As Asset
libAsset2 = assetLib.AppearanceAssets.Item(sColor2)
' try to Copy the asset locally.
Try
localAsset1 = libAsset1.CopyTo(oDoc)
Catch
'assume error means it's already local
localAsset1 = oDoc.Assets(sColor1)
End Try
' try to Copy the asset locally.
Try
localAsset2 = libAsset1.CopyTo(oDoc)
Catch
'assume error means it's already local
localAsset2 = oDoc.Assets(sColor2)
End Try
' change specific body to specific color
Dim oSB1 As SurfaceBody
oSB1 = oDef.SurfaceBodies(1)
oSB1.Appearance = localAsset1 'red
Dim oSB2 As SurfaceBody
oSB2 = oDef.SurfaceBodies(2)
oSB2.Appearance = localAsset2 'cyan
change all bodies to the same color
Dim oDoc As PartDocument = ThisDoc.Document
oDef = oDoc.ComponentDefinition
'define appearance library by name
Dim assetLib As AssetLibrary
assetLib = ThisApplication.AssetLibraries.Item("Autodesk Appearance Library")
sColor1 = "Red"
'define colors to work with
Dim libAsset1 As Asset
libAsset1 = assetLib.AppearanceAssets.Item(sColor1)
' try to Copy the asset locally.
Try
localAsset1 = libAsset1.CopyTo(oDoc)
Catch
'assume error means it's already local
localAsset1 = oDoc.Assets(sColor1)
End Try
' set all solid bodies to the color
Dim oSB As SurfaceBody
For Each oSB In oDef.SurfaceBodies
oSB.Appearance = localAsset1
Next