DOOM Dynamo - Use IDE to modify python code in script

I do a lot of scripting and there are quite a few lines of Python code in it. Revit 2024 API adjustments must be made promptly. In addition, the code inevitably has to be rewritten from IronPython 2.7 to Python 3.8.

I really wanted to avoid doing this with the integrated Dynamo Python editor or copy/paste between Dynamo and VS Code.

Which gave me the crazy idea to take my personal interest in Emacs and learn more about it by creating my first package and mode. The package can be used to read the code from the Dynamo script or custom block and write it into a Python. The Python allows the code to be opened and edited in any Python IDE. Once the code is revised, the Emacs package can be used to overwrite the code in the Dynamo file and be used normally in Dynamo again.

elyo-dynamo
Anyone interested can find the package, installation instructions and configuration template to make getting started as easy as possible.

Question for the community:
How can Dynamo be triggered to re-read the contents of the file (apart from closing and opening Dynamo and/or file). Revit keeps crashing when I adapt Python code that is read and used as a string in the currently open script. Therefore, my guess is that the currently compiled code would have to be discarded, and the newly read code would have to be used and/or compiled.

1 Like

It is possible to use the PythonScript.FromString node to update code saved in an IDE and re-execute it without issue.

Similarly you can have the Python node read from a Python library and allow the imports to update the code.

Both are stable in the context of Dynamo and Revit. in my experience typically issues with Revit crashing are due to failures to account for rerun issues triggered by other issues, where even ‘copy/paste, run’ or even editing in the Dynamo Python environment will cause the same crash.

Thanks for your answer.
Even though I know and use the “Python Script.FromString” block, I still have a lot of code in the scripts with the other Python block, which is why the package supports my work a lot.
In my opinion, the reason why Revit crashes is due to other reasons. Because simply changing the code without re-running the script can result in a crash. My gut feeling is that this has to do with the Python code being compiled and linked to the Revit session in the form of a DLL. I’m not an expert on this topic, which is why I’m very interested in other opinions.

Similarly you can have the Python node read from a Python library and allow the imports to update the code.

Can you describe this in other words? I’m unsure if I understand this correctly. Can you re-use code with “from some.namespace import anything” in scripts? If this is correct, how did you adjust sys.path to allow the code to be imported?

I mean, all of it could be in one file though, no need to split it.

That said, when you do have to split loading a .py file into the Dynamo editor works well, and then it’s just adding from path import * to your imports. You can even preface that with path = IN[0] to load that in as well. And as an added benefit you can load different versions of the functions based on your current Dynamo/Revit version to boot.

As far as your setup crashing, I misinterpreted what you were doing before (that GitHub was a lot of text to translate on a phone screen). If I understand it now, there should be no DLLs involved as neither Dynamo nor Python code is compiled. It seems like you are indicating that you’re forcing program B to write into the file opened by program A without closing/reopening the file. That is going to cause a crash 99% of applications out there, excepting those which keep everything in the active memory/scratch disc. Notepad++ is one example of this as it’s built for live reading logs. Dynamo isn’t.

Reading from an external file instead will ensure stability, the only drawback being you have to package the code with your dyn, but that works significantly better in the context of multiple version support anyway. :slight_smile: