The Entities Property is looking for an array of components which is easy to get in an assembly file using the following code:
Dim blnTopLevelOnly As Boolean = True 'Controls whether program works on all levels of the assembly
Dim lstComponent As Component2() = New Component2(swAssemblydoc.GetComponentCount(blnTopLevelOnly) - 1) {}
Dim objComponents() As Object = swAssemblydoc.GetComponents(blnTopLevelOnly)
For i = 0 To objComponents.GetUpperBound(0)
Dim swComponent As Component2 = objComponents(i)
If Not swComponent.IsHidden(True) And Not swComponent.IsSuppressed Then
lstComponent(i) = swComponent
End If
If swComponent.GetSuppression = swComponentSuppressionState_e.swComponentLightweight Then
lstComponent(i) = swComponent
End If
Next
swModelDoc.ClearSelection2(True)
swAssemblydoc.EditAssembly()
Dim lstComponents As Object = lstComponent
Dim swDisplayStateSetting As DisplayStateSetting = swModelDocExt.GetDisplayStateSetting(swDisplayStateOpts_e.swSpecifyDisplayState)
Dim strDisplayStateNames As String() = New String(1) {}
strDisplayStateNames(0) = strDisplayStateName
Dim lstDisplayStateNames As Object = strDisplayStateNames
swDisplayStateSetting.Names = lstDisplayStateNames
swDisplayStateSetting.Entities = lstComponents
swDisplayStateSetting.Option = swDisplayStateOpts_e.swSpecifyDisplayState
swDisplayStateSetting.PartLevel = False
swDisplayStateSetting.RemoveAppearance = False
My question is how do I populate lstComponents when I'm working with a part file.
I'm trying to write a macro that creates a new display state, and then changes the color of that display state to a specified color in a part file. The original display state must remain the original display state color.
SolidworksApi macros