Deselect All Command

Hey All. I have written an operator that creates a custom object and makes it the active object. It creates the object just fine. However, when I create a second object with that operator, the first object remains selected (though it is no longer the active object). Other operators automatically deselect all other objects. I want mine to do the same. Is there a parameter that I need to add to one of the functions? Or, do I need to use an “invoke()” function? What command do I need, to “deselect all”? Thanks.

operators work normally on the active object only

happy bl

Yes, but my python-made operator is not deselecting the previous active object. The newly created object becomes active (bright orange outline) while the previous object somehow remains selected (dark orange outline). When creating that operator, did I miss a step? Thanks Ricky.

Well, after a bit of research, I found that this invoke() function, added to my operator class, accomplished what I needed:

def invoke(self,context,event):
        return self.execute(context)

Still, I have to wonder, is this the “right way” or the “best way” to do this?

Well, I take it back—I spoke too soon. Now, when I activate my custom operator, the new object is active, and all others are deselected. However, as soon as I use the operator panel, to modify my object, the previous active object again becomes selected, though not active (dark orange outline).

To fix this, I had to move the command: bpy.ops.object.select_all(action=‘DESELECT’) to the first line of my execute() function, so that it runs every time the execute() loop is cycled. Again, is this the “right” or “best” way to do this?

If you are still following or someone comes here:

for ob in bpy.context.selected_objects: = False

Also resort to Blender Stackexchange in the future, awesome website!

1 Like

Thanks @Xerus2000 for your ‘message from the future’

I am learning Python / Blender Python and also ran into a problem playing with a ascript that for selecting and duplicating objects. Seems a good lesson to learn.

Think I’ll also join Blender Stackexchange - I seem to find myself on their pages with the answers often enough.

Thanks again.