Is there a way to omit script editor actions from the undo queue?

When I am prototyping and working with the script editor and the scene at the same time, it’s extremely difficult to work with one undo queue. For example, I will do something in the scene, then write a bunch of code, then need to undo what I did in the scene, but I can’t, because the (tiny) undo queue is filled up with individual character entries from teh script editor.

In Maya, there is a scene undo queue, and a separate one for the script editor. Is anything like that possible in Blender? I’d even settle for just not having one in the script editor if it meant my scene undo wasn’t getting polluted with character entries in the script editor.

5 Likes

@LazyDodo this topic is about coding in blender, so it belongs in the development category.

You should use an external editor or IDE.The internal one is generally not very feature rich. That would also solve you undo problem.

1 Like

I am aware that I can use an external editor, which is what I do when I have something more developed, but I can’t do that when prototyping. Doing so would be incredibly inconvenient and slow workflow way down.

1 Like

Yeah. This drives me insane. I’ve seen similar undo issues in blender with other UI elements or areas. I feel like this is an issue because the work spaces are hacks or something. Or they are not actually considered separate windows / have their own undo states or I don’t know.

I’ve ended up using Visual Studio Code Instead, since it’s free and way more robust. Then I just save and reload my addon over and over. Easier for me than dealing with all the other bugs / issues with the blender code editor / view. :sob::face_with_monocle::man_facepalming:

3 Likes

There’s a lot of issues with the script editor, it being part of the scene being a huge one. Should really take a page from Maya in this regard.

Working in an external editor is fine if you have something more developed, but it’s far, far slower than being able to quickly interact with a scene and commands via tab completion. It’s nearly unusable if you aren’t already an expert with the API.

1 Like

Ok, and you already have increased the undo steps?

Yeah. It’s extremely frustrating if you are new to blender / trying to learn. I guess I’m just used to hitting save on my external script and unchecking / rechecking my addon to reload it.

But yeah, if you are trying to test or learn little commands, it’s rough. There are some Addons that maybe improve / help the internal editor. But I still fear you will run into the undo issue. :sob::sob::hot_face:

1 Like

Btw. there is a reload script command and also a menu entry hidden left to the file menu for that.

Yes, although it’s limited to 256 steps in the UI for some reason? However this isn’t really a solution, as it means I have to save the current state of the script I’ve written, then undo past all my keystrokes, then paste it back into the script editor.

Memory and performance reasons.

No. Thats not true. There are several better ways. One is to transform it to addons but that might be too much boilerplate for your case.

So the simplest way would be to refer to an external file from an internal script
Edit: Sorry I got you wrong with that back pasting comment.

Don’t get me wrong. This are workarounds for you. The argument of having a separate undo stack is good, just not there afaik.

But as I’ve started to argue on external editing. Here’s a code snippet:

import bpy
import os

filename = "my_script.py"

filepath = os.path.join(os.path.dirname(bpy.data.filepath), filename)
global_namespace = {"__file__": filepath, "__name__": "__main__"}
with open(filepath, 'rb') as file:
    exec(compile(file.read(), filepath, 'exec'), global_namespace)

I made it a small addon that adds a menu entry to the File menu to run a file “defaultscript.py” that is placed next to the blendfile directly: (Take a look at the readme)

Edit the “defaultscript.py” with an external editor of your choice just like you did with the internal one

1 Like

@CMK_blender This is not going to relieve you from the Undo pains, but you may find some add-ons which may ease working the Blender Text editor: https://blenderartists.org/t/essential-text-editor-add-ons-for-coders/1163857
The is also an application template, which installs some of the “essential add-ons”: https://github.com/tin2tin/Script_Editing

1 Like

HI updated the post above and here is an example for autocompletion:

1 Like

The blender development category is aimed at doing development on blender’s codebase for coding in blender there is the python section, i should have indeed moved it there instead.

2 Likes

You’d have to jump through a few hoops to set it up, but VS Code can be configured with Blender’s python API for autocompletion and code execution…

Thanks–does it have a connection to the current scene, or is it just generic tab completion?

I haven’t used it myself, just ran into it when I was investigating a blender bug involving the python api - might find someone more familiar with it on the official blender chat site at https://blender.chat

Some notes…

  • Having the text editor group undo more usefully is a known issue https://developer.blender.org/T68068
  • Text data-blocks can be referenced by other library data (freestyle modifiers & nodes for example). So they can’t have their own separate undo stack - at least not entirely separate.
  • As has been suggested, you’re best off to do all your Python coding outside of Blender either as an add-on, or use a stub-script to call out to external files if you want to keep your scripts in Blender.

If this is necessary to maintain, an editor which retained this function could be split off into a separate module. Having a script editor unlinked to scene data is very useful. A parallel issue: it’s also problematic that the script editor is emptied on new scene creation.

This is above, but external coding which doesn’t have direct access to the current scene lacks the function I am seeking here. Stub-script?

2 Likes

Great. When I went there, they told me to come here or stack exchange. When I come here, they tell me to go to stack exchange or blender chat. When I went to stack exchange, I am told to go to blender chat or come here.

This is a bit tiresome.