Skip to main content
deleted 571 characters in body
Source Link
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.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.

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 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.

One 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 

The other, pointed out in the comments, is that the last statement should be OBJS.hide_select = True.

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: Having the broken code in my answer is confusing people in the comments. I've removed it and left only my working code above.

added 73 characters in body
Source Link
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 The 3rd line object.select_set(False) also deselectsis debugging and prints the names of the objects you are marking as hidden from selectionit's deselecting. If Take it out if you don't want to leave them selected, then leave that line outthe noise.

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.

TheOne 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 

The other, pointed out in the comments, is that the last statement should be OBJS.hide_select = True.

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 

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 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.

One 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 

The other, pointed out in the comments, is that the last statement should be OBJS.hide_select = True.

added 198 characters in body
Source Link
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 

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.

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 

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 
Source Link
Marty Fouts
  • 33.5k
  • 10
  • 37
  • 80
Loading