1
$\begingroup$

I'm writing an add-on for Blender. Typically to test my code I have a massive script that has all the details so it can register all the operators, UI Panels etc when I run it through the text editor.

Unfortunately, this means I have a mess of a script that has multiple classes and methods spread out. This is hard to manage and isn't great architecture. Of course in typical IDEs you would break components out into separate files, and for release you would typically bundle them in a .zip which is installed the normal way through Blender. Refactoring one script into multiple scripts at the end of production is cumbersome, and maintaining both a Blender Test script with everything and a Library for my IDE is cumbersome.

Is there a better way to write my scripts as a library without needing to reinstall it as an an addon, or making a massive conglomerate script to run in the Text Editor?

I use PyCharm because I like it, but I know of the VSC Blender Addon. I have used VSC before but I swapped to Jetbrains products because they played a bit nicer with other tools (mainly Unity.)

$\endgroup$
4
  • $\begingroup$ Possibly relevant: blender.stackexchange.com/questions/33603/… $\endgroup$
    – Rug
    Sep 21, 2021 at 19:48
  • $\begingroup$ I use Vscode with the Blender dev extension by Jacques Lucke and it's working pretty well (on windows at least). If you're interested make sure you follow this step by step b3d.interplanety.org/en/… $\endgroup$
    – Gorgious
    Sep 22, 2021 at 9:14
  • $\begingroup$ Cheers! If i ever try VSC again il make sure i try that out $\endgroup$
    – Rug
    Sep 22, 2021 at 21:23
  • $\begingroup$ It's pretty handy because you can launch blender directly from vscode, and the terminal persists if blender crashes. Also you can set it up so addons automatically reload when you save your file in vscode. $\endgroup$
    – Gorgious
    Sep 23, 2021 at 5:41

1 Answer 1

2
$\begingroup$

I'm working a large project as well. I keep my modules in project_folder/libs/. I have to manually add my libs to the path with code like this:

import sys
import os
local_module_path=os.path.join(os.path.dirname(os.path.abspath(__file__)),'libs')
if local_module_path not in sys.path:
    sys.path.append(local_module_path)

This is similar to MutantBob's answer.

Of course __file__ references the current running file, so the code adds libs under that.

$\endgroup$
2
  • $\begingroup$ Do you still edit outside of Blender using a separate IDE? $\endgroup$
    – Rug
    Sep 21, 2021 at 21:13
  • $\begingroup$ Yes, the built-in editor is horrible. Notepad++ for heavy editing and Spyder for algorithm test and design. $\endgroup$
    – Ron Jensen
    Sep 21, 2021 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .