Setting Colors from a STEP model not always working

Hello,

We have an application that models a printed circuit board (PCB) using electronic components imported from STEP models and primitives
to define the other objects on the board.

We import each STEP model and add it to the board model and then set the color of the added shape(s) in the board model to the color
of the shapes in the imported document.

The problem is that it sometimes works and other times not.

To set the color, this is what we do:
-------------------------------------------------------------------------------------------------
if( pStepModelDocument->GetColorTool()->GetColor(modelShape, XCAFDoc_ColorSurf, surfColor) )
{
mpBoardDocument->GetColorTool()->AddColor(surfColor) ;
mpBoardDocument->GetColorTool()->SetColor(partShape, surfColor, XCAFDoc_ColorSurf) ;
}
// Note: The above is done for all three color types.
-------------------------------------------------------------------------------------------------
I've seen some other posts in this forum that are similar but did not find any that provided a solution.

Do you have any idea what might be wrong with this code?

Thanks.