Skip to main content
2 of 4
added 198 characters in body
Marty Fouts
  • 33.5k
  • 10
  • 37
  • 80

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.select_set(False)
    object.hide_select = True

This isn't exactly what you asked for. the 4th line object.select_set(False) also deselects the objects you are marking as hidden from selection. If you want to leave them selected, then leave that line out.

EDIT: I was aware that the 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.

The reason this works and the code you posted doesn't is that your posted code 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 
Marty Fouts
  • 33.5k
  • 10
  • 37
  • 80