Assigning Component Level Colours

Hello, I'm starting to learn API coding and for my current project I am trying to assign part colours at the component level in an assembly so as not to overwrite the original part colour.  The script would be simple, simply select the component to be coloured then run the macro and it will update the colour.

From the start, how would I assign the currently selected part in the api code?

Cheers

-Robin

SolidworksApi macros