Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to work with multiple script files #33

Open
rsaccon opened this issue Nov 14, 2023 · 5 comments
Open

How to work with multiple script files #33

rsaccon opened this issue Nov 14, 2023 · 5 comments

Comments

@rsaccon
Copy link

rsaccon commented Nov 14, 2023

The currently supported workflow seems to support only one single script. I would like to split my project into multiple files where I can import modules from the main script. Is it somehow possible ?

@alphadito
Copy link
Contributor

Here's how I tackle this:

In Blender I have a 'Text Editor' area opened to a 'reload.py' file. After making some edits to the modules which contain tree definitions you just click the play button to run the reload script which you can use to reload all your trees.

image

All files are in the same folder

#reload.py
import sys
import pathlib
import importlib
import bpy

current_text = bpy.context.space_data.text
path=str(pathlib.Path(current_text.filepath).parent.resolve())
sys.path.append(path)

import othermodule, somemodule

def reload_modules():
    importlib.reload(othermodule)
    importlib.reload(somemodule)
   
reload_modules()
# othermodule.py
from geometry_script import *

@tree
def othertree():
    return cube().mesh
# somemodule.py
from geometry_script import *
from othermodule import *

@tree
def sometree():
    mesh = othertree()
    # ...
    return mesh

You have to be careful about the order in which you reload the modules. If you reload tree1 after tree2 which uses tree1 some links to tree1 within tree2 may be broken.

@rsaccon
Copy link
Author

rsaccon commented Nov 15, 2023

Very clever. Works perfectly. Thanks a lot.

@rsaccon rsaccon closed this as completed Nov 15, 2023
@carson-katri
Copy link
Owner

I’d like to reopen this to consider a possible interface for selecting folders to link.
It should also be possible to avoid breaking links when nodes rebuild.

@carson-katri carson-katri reopened this Nov 15, 2023
@rsaccon
Copy link
Author

rsaccon commented Nov 15, 2023

That would be great. On one blender addon I messed around with, I had a reimport of everything as soon as a filechange on a monitored directory was detected (by a timer based polling for file timestamps changes, if I remember properly).

@rsaccon
Copy link
Author

rsaccon commented Nov 16, 2023

Just an update to me previous comment: the watch-directory-and-reimport-on-filechange addon I was using, here is the link to it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants