Dealing with this in scripts is a pain in the arse. To select faces on a single object with a specific material assigned you need to go through every material and every face in the scene and then filter out the ones on the object you're interested in. This makes it really, really slow so any script you write is a bad one.…