Maniphest T80581

Selecting hidden object with script does not activate it in outliner
Closed, Archived

Assigned To
Richard Antalik (ISS)
Authored By
Andi McClure (mcc111)
Sep 8 2020, 3:42 AM
Tags
  • BF Blender
  • Python API
Subscribers
Andi McClure (mcc111)
Campbell Barton (campbellbarton)
Richard Antalik (ISS)

Description

System Information / Blender Version
Operating system: Mac OS X 10.13.6 (17G10021)
Graphics card: Intel Iris Graphics 6100
Repro'd on:
2.9.0
2.83.5 (LTS)
2.91.0-5c2ac8520e07 (nightly)

Also repro'd on: 2.29.0 on Windows 10 18363 with Radeon R9 390

Exact steps for others to reproduce the error

  1. Open file
  2. Run script

Event Timeline

Andi McClure (mcc111) created this task.Sep 8 2020, 3:42 AM
Richard Antalik (ISS) added a subscriber: Richard Antalik (ISS).Sep 14 2020, 5:07 PM

I am not sure if I understand the problem.

When I run your script, it selects object "zap". Is is not drawn as selected in outliner, that is reported as bug if I am not mistaken. But it selected (you can unhide it with KB shortcut).

Or am I missing something?

Richard Antalik (ISS) changed the task status from Needs Triage to Needs Information from User.Sep 14 2020, 5:07 PM
Andi McClure (mcc111) changed the task status from Needs Information from User to Needs Triage.Sep 15 2020, 1:18 AM
Andi McClure (mcc111) assigned this task to Richard Antalik (ISS).

Hi Richard,

I agree that when the script is run, the object is not drawn as selected in outliner.

Can you help me understand, how could I detect that an object is "selected" without it being drawn as selected in the outliner? When you say "it selects object 'zap'", how did you tell that the object is selected?

As far as I can tell, the object is *not* selected. Here is my reasoning.

Say that I open my mirrorroom-fixed5.blend test file. I go to the scripting tab, and I add the single line bpy.ops.object.duplicate() to the end of the script. So the script is now

import bpy

# MUST SET ZAP RENDERABLE BEFORE RUNNING, THEN UNRENDERABLE AFTER RUNNING

# Find objects
zap = bpy.data.objects['zap']

# Clear old zaps
bpy.ops.object.select_all(action='DESELECT')

bpy.ops.object.select_pattern(pattern="zap")
zap.select_set(True)
bpy.ops.object.duplicate()

Testing in 2.9.0, if the eye icon next to "zap" in the outliner is closed, and I run this script, nothing happens. Nothing at all.

If the eye icon is open and I run the script, "zap" is duplicated and a new object zap.001 appears in the outliner and also in the viewport.

I see the same results in 2.91.0-5c2ac8520e07.

So the object is not indicated as selected in the GUI. And when I run a scripting operation on the selected object, the operation does not recognize the object as selected.
It does not seem the object is "selected" in any meaningful sense. Am I missing something?

Richard Antalik (ISS) added a comment.Sep 15 2020, 11:06 AM

Issue in this case is that bpy.ops.object.duplicate() will not operate on hidden object. You can select "zap" object and press shift+D and nothing will happen.

Since I can't find any open report for outliner not being synced, I will confirm this report

Richard Antalik (ISS) renamed this task from Scripts cannot select hidden objects [may be documentation issue] to Selecting hidden object with script does not activate it in outliner.Sep 15 2020, 11:12 AM
Richard Antalik (ISS) changed the task status from Needs Triage to Confirmed.
Richard Antalik (ISS) updated the task description.
Richard Antalik (ISS) added a project: Python API.
Andi McClure (mcc111) added a comment.Sep 15 2020, 11:01 PM

"Issue in this case is that bpy.ops.object.duplicate() will not operate on hidden object"

This is not a documented property of bpy.ops.object.duplicate.

https://docs.blender.org/api/blender_python_api_current/bpy.ops.object.html#bpy.ops.object.duplicate

So I think there is still a documentation issue, that functions that do not duplicate viewport-hidden (not the only type of hidden!) objects are not documented as doing this.

Should I file a separate issue for that? (Since this is now officially a bug for the outliner.)

Richard Antalik (ISS) added a comment.Sep 16 2020, 11:35 AM
In T80581#1016551, @Andi McClure (mcc111) wrote:

"Issue in this case is that bpy.ops.object.duplicate() will not operate on hidden object"

This is not a documented property of bpy.ops.object.duplicate.

https://docs.blender.org/api/blender_python_api_current/bpy.ops.object.html#bpy.ops.object.duplicate

So I think there is still a documentation issue, that functions that do not duplicate viewport-hidden (not the only type of hidden!) objects are not documented as doing this.

Should I file a separate issue for that? (Since this is now officially a bug for the outliner.)

If we get to such details, it is probably better to look at the actual implementation. Looking at description of other operators I see very short brief sentences that would certainly not be unconditionally correct.

I don't think we can accept such report really, because current description is good enough for current "standard".

Campbell Barton (campbellbarton) closed this task as Archived.Sep 17 2020, 1:53 AM
Campbell Barton (campbellbarton) added a subscriber: Campbell Barton (campbellbarton).

Most operators only operate on visible-selected, this is not something which needs to be documented on each operator as it's assumed.

Closing.

Andi McClure (mcc111) added a comment.Sep 17 2020, 2:01 AM

Wait, but what about the problem that an item is selected by the script but doesn't show up as selected in the outliner? It seems VERY weird for an item to be selected but the user to not have visual feedback it's selected.

Campbell Barton (campbellbarton) added a comment.EditedSep 17 2020, 7:00 AM

If I first un-hide all (alt-h) in the 3D view, then run the script.
This selects the object in the outliner, even if it's previously unselected.

What would you expect to happen?

Campbell Barton (campbellbarton) reopened this task as Needs Information from User.Sep 17 2020, 7:00 AM
Richard Antalik (ISS) added a comment.Sep 17 2020, 3:01 PM
In T80581#1017409, @Campbell Barton (campbellbarton) wrote:

If I first un-hide all (alt-h) in the 3D view, then run the script.
This selects the object in the outliner, even if it's previously unselected.

What would you expect to happen?

I would expect selection to be reflected in outliner if "Sync Selection" is enabled regardless of visibility.

Andi McClure (mcc111) added a comment.EditedSep 17 2020, 5:08 PM

As noted in my original bug report (which appears to have had most of its text deleted?) my expected behavior is that viewport visibility (which is after all only one type of visibility) would have no bearing on whether operations can be performed through the scripting interface (since it has no bearing on whether they can be performed through the GUI— the GUI can select and duplicate viewport-hidden items). If there is some historical reason why this is not the case, I would expect to be given a trap door, like a visibility="ALL" argument, to let me operate on the viewport-hidden items. And if there is some design reason why this is not given, I would expect it to be documented that viewport-hidden objects are excluded from certain operations, and which ones— I would expect this to be listed in the function documentation, and if not there, somewhere else. It was not "assumed" by me that viewport-hidden objects can't be operated on because this fact is not documented anywhere I can find.

My use case is that I had a .blend file with a hidden "template" object and a desire to write a script that made many copies of the template object in various locations. The template object was not intended to be seen or rendered, only to be used as a basis for the script. I skimmed the various quickstart/overview/best practice documents https://docs.blender.org/api/current/index.html, looked at some sample code, and looked at the function references. And then wrote a script (bpy.ops.object.select_pattern(pattern="zap") followed by bpy.ops.object.duplicate()) that did literally nothing, and I lost a number of hours trying to figure out why nothing was happening. I had no reason to believe that clicking the little eyeball icon was somehow highly significant to the scripting interface.

I now find out from Mr. Antalik that select_pattern/select_set on a viewport-invisible object in fact *half*-selects the object?— it sets it selected in some sense?, but it does not highlight it in the scene view. To me, this is the most unexpected thing of all. My *general* expectation— primed by the Python functions that are printed out in the scripting tab— is that the GUI and the scripting interface are operating on the same data and use the same primitives.

"Viewport-hidden objects can't be selected" is a surprising rule to me, but once it is explained to me I understand it. "Attempting to select a viewport-hidden object puts it into some strange state the GUI does not reflect" sounds alarming. I would expect *everything* I do in a script is reflected in the GUI. I think even if none of my expectations above are correct, Mr. Antalik's expectation that selections are reflected in the outliner is.

Campbell Barton (campbellbarton) closed this task as Archived.Sep 20 2020, 7:28 AM

While operators are accessible from Python they are primarily for user interaction, for this reason they operate on visible elements.

Closing since this is working as intended.

Andi McClure (mcc111) added a comment.Sep 20 2020, 4:07 PM

But, again, in user interaction, all of these operations work completely fine when the elements are viewport-invisible! It is *only* Python that is banned from operating correctly on invisible elements (*and this is not documented anywhere I can find*)