How to use multiple script texts?

Hi, the reason I like script texts more than script files of an addon is because I don’t need to install addon all the time, and in the future I will not need to care which addon file should I install because I will reinstall Blender.

Blender version: 2.83 LTS

Text name: Main.py
Register checkbox: Checked

import bpy
import MyModule # Error: ModuleNotFoundError: No module named 'MyModule'

c = MyClass(123)
c.Print()

Text name: MyModule.py
Register checkbox: Checked

class MyClass:
    def __init__(self, x):
        self.x = x
    def Print(self):
        print("x =", self.x)

How to fix that error? I don’t know what should be the name of the text “Main.py”. Thanks.

Sometimes, I don’t get answers by others. Now, my blend file has a very long single script text because I don’t know how to separate my script. Sometimes, I don’t want to touch parts of my code which are perfect, but I cannot because everything is in one single text, that’s very sad.

I’m sorry for my old coding style in first post, function names should be lower case and use underscores.

I heard from other forum that when you found the solution by yourself then you come back, it will help people in the future.

1 Like