How to Set the Custom Depth Stencil Value for existing static mesh actors

Hi guys, I am working on a building segmentation project but I am new to C++ and unreal engine. I have a Revit model imported to unreal. The ID name of the the static mesh actors are the categories in Revit.

I would like to write a code to assign the same custom depth stencil value to all the static mesh actors and actors in the same category should have the same stencil value(i.e. Walls_Basic_Wall_Retaining_-_300mmm_Concrete 1 to 9 should have the same custom depth stencil value) I have a list of all categories in the model to reference to. I have found two functions that can do the job
(UPrimitiveComponent::SetRenderCustomDepth | Unreal Engine Documentation
UPrimitiveComponent::SetCustomDepthStencilValue | Unreal Engine Documentation
but I am not sure how to use them and what class should I write my code on. Can anyone give me some help with this? Thank you so much!!!