@e_jansonLT2PV
Thank you for answering my questions, although I think I have a solution that doesn't require them and you can keep patterning features.
So the code below requires the names of the extrusions you want to color (line 3-4) and the appearance names used to color them (line 8-9). It will then copy the matching library appearances to the document so they can be used (line 29-48), it will color the listed extrusions (line 52-65) as they are not 'part' of any pattern and the last section (line 69-114) will go through all pattern elements and all the faces each of them contains and check if the feature that created each face was an extrude feature listed at the beginning. If so, it colors them.
iLogic rule:
'Set list of features to color
Dim sFeatureName As New ArrayList
sFeatureName.Add ("Box1")
sFeatureName.Add ("Pallet1")
'Set list of appearances to use
Dim sFeatureColorName As New ArrayList
sFeatureColorName.Add ("Yellow")
sFeatureColorName.Add ("Orange")
'Check if sufficient colors are defined
If sFeatureColorName.Count < sFeatureName.Count Then
MessageBox.Show("Not enough appearances in the list, aborting...","iLogic: Rule Name",MessageBoxButtons.OK)
Exit Sub
End If
'Set various references
Dim oDoc As PartDocument = ThisApplication.ActiveEditDocument
Dim oCompDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oPartFeats As PartFeatures = oCompDef.Features
'Create transaction
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "iLogic: Rule Name")
'Declarations
Dim oLibAsset As Asset
Dim oLocAsset(sFeatureColorName.Count-1) As Asset
Dim i As Integer
'Iterate through all listed appearances
For i = 0 To sFeatureColorName.Count-1
Try
'Try to access the appearances asset from the document appearances library
oLocAsset(i) = oDoc.AppearanceAssets(sFeatureColorName(i))
Catch
'Get listed appearance from library
oLibAsset = ThisApplication.AssetLibraries.Item("Inventor Material Library").AppearanceAssets(sFeatureColorName(i))
'Copy the asset to the document appearances library
oLocAsset(i) = oLibAsset.CopyTo(oDoc)
End Try
Next i
'Declarations
Dim oExtFeat As Inventor.ExtrudeFeature
'Iterate through all extrusion features
For Each oExtFeat In oCompDef.Features.ExtrudeFeatures
'Check if extrusion is in the feature list and color it if so.
For i = 0 To sFeatureName.Count-1
If oExtFeat.Name = sFeatureName(i) Then
oExtFeat.Appearance = oLocAsset(i)
Exit For
End If
Next i
Next
'Declarations
Dim oRecPatFeat As RectangularPatternFeature
Dim oPatElem As FeaturePatternElement
Dim oFace As Face
Dim oObject As Object
Dim bListed As Boolean
'Iterate through all rectangular patterns
For Each oRecPatFeat In oPartFeats.RectangularPatternFeatures
'Iterate through all pattern elements
For Each oPatElem In oRecPatFeat.PatternElements
'Check if element contains faces
If oPatElem.Faces.Count > 0 Then
'Iterate through all faces in the element
For Each oFace In oPatElem.Faces
'Iterate through all source features of the face
For Each oObject In oFace.[_CreatedByFeatures]
'Check if source feature is an extrusion
If oObject.Type = kExtrudeFeatureObject Then
'Check if extrusion is in the feature list
For i = 0 To sFeatureName.Count-1
If oObject.name = sFeatureName(i) Then
bListed = True
Exit For
End If
Next i
'Color face when extrusion was listed and stop iterating source features
If bListed = True Then
oFace.Appearance = oLocAsset(i)
bListed = False
Exit For
End If
End If
Next
Next
End If
Next
Next
'End transaction
oTrans.End