Hello from Japan,
Try this code!
Please use freely.
Sub IColor()
Dim doc As AssemblyDocument
Dim designView As DesignViewRepresentation
Dim viewFound As Boolean
Dim repManager As RepresentationsManager
Set doc = ThisApplication.ActiveDocument
Set repManager = doc.ComponentDefinition.RepresentationsManager
viewFound = False
For Each designView In repManager.DesignViewRepresentations
If designView.Name = "IColor" Then
viewFound = True
Exit For
End If
Next
If Not viewFound Then
Set designView = repManager.DesignViewRepresentations.Add("IColor")
End If
designView.Activate
Dim occ As ComponentOccurrence
Dim index As Integer
Dim localAsset As Asset
index = 0
For Each occ In doc.ComponentDefinition.Occurrences
Set localAsset = GetAsset(doc, index)
occ.Appearance = localAsset
index = index + 1
If index = 16 Then
index = 0
End If
Next
End Sub
Private Function GetAsset(doc As AssemblyDocument, colorNumber As Integer) As Asset
Dim localAsset As Asset
Dim colorName As String
colorName = "IColor" & colorNumber
On Error Resume Next
Set localAsset = doc.Assets.Item(colorName)
If Err Then
Set localAsset = doc.Assets.Add(kAssetTypeAppearance, "Generic", colorName, colorName)
Dim tobjs As TransientObjects
Set tobjs = ThisApplication.TransientObjects
Dim color As ColorAssetValue
Dim red As Integer
Dim green As Integer
Dim blue As Integer
Dim high As Integer
Dim low As Integer
If colorNumber < 8 Then
high = 255
low = 30
Else
high = 127
low = 0
End If
If colorNumber And 1 Then
red = high
Else
red = low
End If
If colorNumber And 2 Then
green = high
Else
green = low
End If
If colorNumber And 4 Then
blue = high
Else
blue = low
End If
localAsset.Item("generic_diffuse").Value = tobjs.CreateColor(red, green, blue)
Dim floatValue As FloatAssetValue
Set floatValue = localAsset.Item("generic_reflectivity_at_0deg")
floatValue.Value = 0.1
Set floatValue = localAsset.Item("generic_reflectivity_at_90deg")
floatValue.Value = 0.1
End If
On Error GoTo 0
Set GetAsset = localAsset
End Function
Best Regards,
=====
Freeradical
Hideo Yamada