Maniphest T79295

toolsettings.use_snap registers an undo when used in conjunction with bpy.ops.transform.translate
Closed, Resolved

Assigned To
Germano Cavalcante (mano-wii)
Authored By
Ethan Simon (razed)
Jul 26 2020, 8:10 PM
Tags
  • BF Blender
  • Python API
Subscribers
Ethan Simon (razed)
Germano Cavalcante (mano-wii)

Description

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 451.77

Blender Version
Broken: version: 2.83.0, branch: master, commit date: 2020-06-03 14:38, hash: rB211b6c29f771
Worked: (newest version of Blender that worked as expected)

Short description of error
OK so I have been trying to crack the code for a while now but I think I figured out the error with my code and it may be an error with the API. I have made a modal operator that allows the user to manually change where the origin is placed, with similar functionality to Mayas pivot editing system. The issue lies with using the use_snap option in toolsettings. It does not seem to register undo states properly in conjunction with a translate bpy.ops. Regardless of the context it always seems to register use_snap as true when you go back into the translate undo state, turning it back on.

My theory is the use_snap option is linked to the translate modal when both are used in conjunction and treats it as one, turning it back on when you redo into the translate state. The ideal scenario is the translate modal be separated from toolsettings.use_snap and saves the undo state properly like every other setting changed (if it needed to be mentioned this is the ONLY toolsetting that reacts this way, and conveniently the only option related to the translate modal).

Here is the pastebin for my code. I ripped it from my scripts so I tried to make it work on its own but if it doesn't it shouldn't be difficult to get it working: https://pastebin.com/d5e0Yzhy

Exact steps for others to reproduce the error
To reproduce the issue using the operator within the paste bin, if you use it on a mesh, undo and then redo back into the operators undo state everything will work as intended except for snapping which turns back on. The intended result is for the snapping to be how it was post-use of the operator. This issue happens if you undo into ANY undo state in which you used the operator, not just if you undo and redo.

Here is a gif to show the issue, after running the operation I simply undo and redo... and there is the issue: https://imgur.com/a/K6kVSE2

I don't have a solution for this problem, so if you somehow do and would be willing to share I would greatly appreciate it.

Event Timeline

Ethan Simon (razed) created this task.Jul 26 2020, 8:10 PM
Ethan Simon (razed) renamed this task from Python API issue - Activating on snapping registers an undo regardless of context to toolsettings.use_snap registers an undo regardless of context.Jul 26 2020, 8:12 PM
Ethan Simon (razed) added a project: Python API.
Ethan Simon (razed) added a comment.Jul 27 2020, 4:05 PM

Maybe this code is automatically getting optimized since toolsettings.use_snap is inherently the same as the snap option in the translate modal? I have never looked at the source code before and cannot write in C++, but I am going to see if I can crack it open and find what I am looking for. If I don't get a response in a few days I will try to simplify the operator to better get to the root of the issue.

Ethan Simon (razed) renamed this task from toolsettings.use_snap registers an undo regardless of context to toolsettings.use_snap registers an undo when used in conjunction with bpy.ops.transform.translate.Jul 27 2020, 4:08 PM
Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Needs Information from User.Jul 28 2020, 9:42 PM
Germano Cavalcante (mano-wii) added a subscriber: Germano Cavalcante (mano-wii).

Thanks for the report. Unfortunately the scenario described is too time consuming for us to track down, we require the bug reporter to narrow down the problem.
Also, this bug tracker does not provide support for unofficial addons/scripts.
If you are sure that the problem is with blender, please simplify the script to just a few lines.


I have made a modal operator that allows the user to manually change where the origin is placed,

I don't know what the intention is, but this feature already exists in blender:
https://docs.blender.org/manual/en/dev/scene_layout/object/editing/transform/control/options.html#bpy-types-toolsettings-use-transform-data-origin

Ethan Simon (razed) added a comment.Jul 28 2020, 11:21 PM

Thanks for the response Germano, this issue is not directly related to my own personal scripts, it could happen in any script utilizing enabling snapping automatically.

https://pastebin.com/d5e0Yzhy here is a simplified version of the operator which is completely commented to better explain what is going on. I also included an example where it works as intended to kind of drive the point home.

So for the intention. This specific tool merges the use of affect only origins (or an alternate method using empties since versions older than 2.82 don't support the feature) to allow the user to one click translate the origin wherever they please.

Ethan Simon (razed) changed the task status from Needs Information from User to Needs Information from Developers.Jul 28 2020, 11:23 PM

I think this is the right thing to do? Apologies if I am misusing this.

Campbell Barton (campbellbarton) moved this task from Backlog to Bugs (Context) on the Python API board.Aug 23 2020, 8:47 AM
Philipp Oeser (lichtwerk) changed the task status from Needs Information from Developers to Needs Triage.Nov 24 2020, 12:08 PM
Ethan Simon (razed) updated the task description.Nov 24 2020, 12:48 PM
Germano Cavalcante (mano-wii) added a comment.Nov 24 2020, 1:25 PM

I can't reproduce the problem (has it been solved yet?)
Btw, there is a known issue with the design of undo steps that is being explained in T56163: Improve MemFile Undo (for general use)

Ethan Simon (razed) added a comment.EditedNov 24 2020, 2:37 PM

@Germano Cavalcante (mano-wii) I tested on the 2.92 alpha and it seems to not be occurring any longer. I guess that means it was solved? Would be curious to know what fixed it, but otherwise seems like that covers it :)

Germano Cavalcante (mano-wii) closed this task as Resolved.Nov 24 2020, 2:48 PM
Germano Cavalcante (mano-wii) claimed this task.

Good to know it was resolved :)
We could ask more developers or do git bisect to find out which commit solved the problem.
But for now I will just close as resolved.