bpy.ops.select_pattern() returns {FINISHED} even if object wasn't successfully selected #51310

Closed
opened 2017-04-24 17:19:30 +02:00 by Henrik Berglund · 7 comments

System Information
Win8.1, GTX1070

Blender Version
Broken:2.78c e92f235283

Short description of error
bpy.ops.select_pattern() returns {FINISHED} even if object wasn't successfully selected. For example if you're trying to select something on a layer that isn't visible. I use this in my export script. I've got the mesh and rig on different layers. Sometimes I forget to show the layer with the rig on and export only the mesh. When this is imported into UE4 using reimport strange things happen.

I think this operator should return an error if nothing was actually selected, in case for example you're trying to select something not visible. Or automatically showing the layer the object was on if nothing was selected at first.

Exact steps for others to reproduce the error

  1. Add a cube.
  2. Deselect cube.
  3. Show only layer 2 by clicking on layer 2 without shift.
  4. Type
    bpy.ops.object.select_pattern(pattern="Cube")
    in python console (assuming name of the cube was Cube).
  5. Go to layer 1. It's not selected.

Expected: error when trying to select unselectable object.

**System Information** Win8.1, GTX1070 **Blender Version** Broken:2.78c e92f235283 **Short description of error** bpy.ops.select_pattern() returns {FINISHED} even if object wasn't successfully selected. For example if you're trying to select something on a layer that isn't visible. I use this in my export script. I've got the mesh and rig on different layers. Sometimes I forget to show the layer with the rig on and export only the mesh. When this is imported into UE4 using reimport strange things happen. I think this operator should return an error if nothing was actually selected, in case for example you're trying to select something not visible. Or automatically showing the layer the object was on if nothing was selected at first. **Exact steps for others to reproduce the error** 1. Add a cube. 2. Deselect cube. 3. Show only layer 2 by clicking on layer 2 without shift. 4. Type bpy.ops.object.select_pattern(pattern="Cube") in python console (assuming name of the cube was Cube). 5. Go to layer 1. It's not selected. Expected: error when trying to select unselectable object.
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @cyaoeu

Added subscriber: @cyaoeu

Added subscriber: @Sergey

Added subscriber: @Sergey

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sergey Sharybin self-assigned this 2017-05-15 13:59:03 +02:00

FINISHED means that operator execution finished, it does not denote anything whether operator changed something or not. So there is no bug here, since the operator did not fail or anything, it just didn't find anything selectable.

FINISHED means that operator execution finished, it does not denote anything whether operator changed something or not. So there is no bug here, since the operator did not fail or anything, it just didn't find anything selectable.
Author
Member

I think it should fail (raise an error) if nothing was selected. If you expected something to be selected (which you probably do when running an operator called select_pattern) and nothing was selected it's an undesirable result.

I'm using select_pattern in my export scripts and if select_pattern didn't do anything in my script for some reason strange things happen. For example I was trying to select my rig, but it was on a hidden layer, so now I'm exporting my character without a rig. Thankfully the game engine I'm using complains when reimporting such an .fbx (in caps) so I don't mess anything up, but things like this shouldn't happen.

Now I'm checking if I actually selected something using select_pattern after that code row, and if I didn't I raise an exception, but doing this after you used select_pattern just feels strange. I would much rather use try: except:.

I think it should fail (raise an error) if nothing was selected. If you expected something to be selected (which you probably do when running an operator called select_pattern) and nothing was selected it's an undesirable result. I'm using select_pattern in my export scripts and if select_pattern didn't do anything in my script for some reason strange things happen. For example I was trying to select my rig, but it was on a hidden layer, so now I'm exporting my character without a rig. Thankfully the game engine I'm using complains when reimporting such an .fbx (in caps) so I don't mess anything up, but things like this shouldn't happen. Now I'm checking if I actually selected something using select_pattern after that code row, and if I didn't I raise an exception, but doing this after you used select_pattern just feels strange. I would much rather use try: except:.

Operator's return value is not only used for making decisions in the user's code, that return value is mainly used by the WindowManager to make decision how to unroll even handling after the operator's exec() finished, whether stuff needs to be put to undo buffer and so. Changing behavior of particular operator for a specific usecase is quite unlikely. You will really quickly run into conflict of interest of different script writers.

So just stick to the current design decision and live with that would be my suggestion.

Operator's return value is not only used for making decisions in the user's code, that return value is mainly used by the WindowManager to make decision how to unroll even handling after the operator's exec() finished, whether stuff needs to be put to undo buffer and so. Changing behavior of particular operator for a specific usecase is quite unlikely. You will really quickly run into conflict of interest of different script writers. So just stick to the current design decision and live with that would be my suggestion.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#51310
No description provided.