How do I change viewport display of multiple objects?

Hi guys, I’m trying to use python to change multiple selected object from ‘textured’ to ‘wire’ in viewport display
Capture

But when I write some code lines, it did not work as I want, only activate object changed to ‘wire’

Is there anyway to solve this problem?
Thank you and have a nice day!

use the obj. You are still using the context active object in your loop

Or just Hold the alt key :slight_smile:

@BD3D I searched on Blender 3.0.0 Python API and it only showed ‘bpy.context.selected_objects’. There is no ‘obj.’ in search result

You wrote for obj in bpy.context.selected_objects
What do you think this obj Is ? :relieved:

Yes, I wrote ‘for obj in bpy.context.selected_objects’ to use ‘for’ loop. Am I wrong from this code line?

I solved the problem, thanks!

hEY GUYS, SO WHAT WAS THE FINAL SOLUTION? AND HOW TO INTERACT WITH THE “IN FRONT” VIEWPORT DISPLAY OPTION?

The solution was:

import bpy
for obj in bpy.context.selected_objects:
    obj.display_type = “WIRE”

The answer to your second question- right click on the In Front box, copy full data path, and switch the the line above to incorporate that instead

The solution is:

lst = bpy.context.selected_objects
        for obj in range(len(lst)):
            lst[obj].display_type = 'WIRE'

FYI, it would be much more efficient to do this:

import bpy
for obj in bpy.context.selected_objects:
    obj.display_type = 'WIRE'

Adding a range function, len, and list index lookup is slower than just directly iterating through the list and should be avoided where possible

awsome, so i was close… but i can’t figure out how to let the script un-flag the “In Front” display option, any guess? thanks a lot!

Set it to True (enabled) or False (disabled) - i.e.
obj.whatever_the_path_is = True

If you just want to toggle it, do:
obj.whatever_the_path_is = not obj.whatever_the_path_is

how to read how is named/the path i need?

use the data path, which you get by right clicking on the checkbox

awesome, it worked… i was trying to copy the path using the wrong button…

here’s:

import bpy
for obj in bpy.context.selected_objects:
obj.show_in_front = False

thank you all guys

nice! thank you for your contribution