You normally do this sort of thing with a for loop; using bpy.context.selected_objects
. That's a list of all of the objects you have selected.
Here's an example:
import bpy
for object in bpy.context.selected_objects:
print(object.name)
object.hide_select = True
This isn't exactly what you asked for. The 3rd line is debugging and prints the names of the objects it's deselecting. Take it out if you don't want the noise.
EDIT: I was aware that Having the broken code you posted was something you got from the 'net, because you said so. I posted the correction simply as an example of the fact that formatting matters in Python.
One reason this works and the code you posted doesn't is that your posted codemy answer is indented improperly. Properly indent the last line to make it part of the for loop
Properly indented your code would like like this:
import bpy
SEL_OBJS = bpy.context.selected_objects
ACT_OBJ = bpy.context.active_object
for OBJS in SEL_OBJS:
bpy.context.object.hide_select = True
The other, pointed outconfusing people in the comments, is that the last statement should be OBJS.hide_select = True
. I've removed it and left only my working code above.