Is there a quick way to randomize colors for multibody parts or assemblies?

CAD

Looking for a fast method to assign random colors to bodies or components in a multibody part or assembly.

Goal is better visual separation during early DFM / layout stages, while keeping performance reasonable (not diving into heavy appearance/render settings).

Is there a built-in option, macro, or workflow for this?

GPT SAYS;

This is one of those “why is this not a button already” moments. SolidWorks loves making you earn basic quality-of-life stuff.

There is no native “randomize colors” button

Because that would make sense.

Your real options:

1. Display States + manual assign (baseline)

  • Create a display state
  • Ctrl-select bodies/components
  • Assign appearances → slow, boring, what most people suffer through

2. Macro (the real solution)

You want:

  • iterate bodies/components
  • assign random RGB
  • apply at body/component level (not face)

This is the correct path.

Minimal VBA macro (multibody part example):

Dim swApp As Object
Dim swModel As Object
Dim vBodies As Variant
Dim swBody As Object
Dim i As Integer

Sub main()

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc

    vBodies = swModel.GetBodies2(0, True)

    Randomize

    For i = 0 To UBound(vBodies)
        Set swBody = vBodies(i)

        Dim r As Double, g As Double, b As Double
        r = Rnd()
        g = Rnd()
        b = Rnd()

        Dim matProps(8) As Double
        matProps(0) = r
        matProps(1) = g
        matProps(2) = b
        matProps(3) = 1 ' ambient
        matProps(4) = 1 ' diffuse
        matProps(5) = 1 ' specular
        matProps(6) = 0.5
        matProps(7) = 0.5
        matProps(8) = 0.5

        swBody.SetMaterialPropertyValues2 matProps, 1, Nothing
    Next i

End Sub

Assembly version is the same idea but loops components instead.

3. Appearances via “Apply to Bodies”

  • Slightly faster than faces

  • Still manual, still annoying

Performance note (the part you were trying to say)

  • Don’t use RealView / textures

  • Stick to flat colors

  • Use display states, not configs → keeps rebuild + graphics light

Bottom line:
No built-in tool because reasons.
Macro is the correct answer.
Reddit will give you 14 wrong ones and one guy who says “just do it manually.”

Posted Apr 9, 2026, 8:03 PM UTC

18
Loading comments…