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.
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.
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.
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.
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.
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.
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
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.
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
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?
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.