Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- # In this example operator, use_snap is being turned on. If you run the operator, commit the modal then
- # undo and then redo toolsettings.use_snap will be turned back on
- # WARNING: This operator only works if there is an active object selected and you are in Object Mode
- class EDITORIGINTEST_OT_edit_origin(bpy.types.Operator):
- bl_idname = "edit_origin_test.edit_origin"
- bl_label = "Edit Origin"
- bl_options = {'REGISTER'}
- def modal(self, context, event):
- if self.finished:
- # Disable use_snap. It is REQUIRED to do it after return {'PASS_THROUGH'} or else it will not
- # disable due to the transform.translate being active, hence my theory of it being automatically
- # optimized with transform.translate's built in snapping option
- context.scene.tool_settings.use_snap = False
- return {'CANCELLED'}
- if event.type in {'LEFTMOUSE', 'RET', 'RIGHTMOUSE', 'ESC'}:
- context.scene.tool_settings.use_transform_data_origin = False
- # Initiate modal end
- self.finished = True
- return {'PASS_THROUGH'}
- return {'PASS_THROUGH'}
- def invoke(self, context, event):
- # Modal end detection
- self.finished = False
- # Turn on use transform data origin
- context.scene.tool_settings.use_transform_data_origin = True
- # Enable use_snap
- context.scene.tool_settings.use_snap = True
- # Translate modal
- bpy.ops.transform.translate('INVOKE_DEFAULT')
- # Modal handler
- wm = context.window_manager
- wm.modal_handler_add(self)
- return {'RUNNING_MODAL'}
- # The reason I consider this broken is because if you use 'context.scene.tool_settings.use_snap'
- # without the translate modal and without registering the undo within bl_options of the operator
- # it will not register the undo and thus undoing and redoing will not result in use_snap being turned back on
- # This is a bit of a redundant example since I think text explains it well enough, but in this
- # example if you were to undo and redo use_snap would not be turned on after undoing and redoing
- class EDITORIGINTEST_OT_toggle_use_snap(bpy.types.Operator):
- bl_idname = "edit_origin_test.toggle_snap"
- bl_label = "Snap Toggle"
- bl_options = {'REGISTER'}
- def execute(self, context):
- context.scene.tool_settings.use_snap = True
- context.scene.tool_settings.use_snap = False
- return {'FINISHED'}
- # Register the operators
- bpy.utils.register_class(EDITORIGINTEST_OT_edit_origin)
- bpy.utils.register_class(EDITORIGINTEST_OT_toggle_use_snap)
- # I understand that this is a niche scenario, and if it would be too difficult to implement a fix I would
- # totally understand. I also made this report in hopes that maybe I missed something in my hours of testing
- # that would make this a non-issue entirely. Any off the books suggestions would be appreciated.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement