Batch renaming of components with a prefix inside a DC component

Hello! Is there a way to rename simultaneously components that are in a DC model?
I have a DC cabinet model, and when I import 2 of them, I would like to be able to rename one of the cabinets and all of its subcomponents with a common prefix like “Cab1_” so the components inside would get the name for example “Cab1_Right side” and “Cab1_Left side” and so on. Similarly rename the second cabinet and all of its subcomponents with a prefix “Cab2_” so the components inside would look like “Cab2_Right side”, “Cab2_Left side” and so on.
This way I could use them in a cutlist program and organize them according to their definition name and this way “group” them so all parts of cabinet 1 would be after each other and not in a random order.

Is there a way to do that?

Yes, you could do this with a Ruby script. Do you want to rename the instances or the definitions for your cutlist program? Can you post an example of the component you want to rename the parts of?