So I have an error which is when I try to import my entire add on as a zip file and enable it, it gives me an error saying there is no module named "save_shader_map".
I know this isn't true because I have structured my add on as a folder. In the folder there are three files, init.py, load_shader_map.py and save_shader_map.py and I can see there is a file called save_shader_map.py in the same folder.
Where I am trying to import the save_shader_map python file is in another file in my addon named load_shader_map.py and the relevant code is here:
#import all libraries including re needed for regex matching
#import Path library to search recursively for files
import bpy, re
import glob
from pathlib import Path
import os
#import from other files required functions and classes
import sys
sys.path.append(".")
#import classes
from save_shader_map import SHADER_PRESETS_UL_items, ShowMessageOperator
#import functions
from save_shader_map import get_preferences, get_selected_folder_presets, json_to_nodes_dict
Now I think the problem is with the sys.path.append("."), because the line where the error of no module found occurs is this line:
from save_shader_map import SHADER_PRESETS_UL_items, ShowMessageOperator
I have tried instead replacing the sys.path.append with the following code which still says there is no module named save_shader_map, so I believe I am importing it incorrectly.
from . import save_shader_map
#import classes
from save_shader_map import SHADER_PRESETS_UL_items, ShowMessageOperator
#import functions
from save_shader_map import get_preferences, get_selected_folder_presets, json_to_nodes_dict
My _init file looks like this:
from . import save_shader_map
from . import load_shader_map
import time
import bpy
bl_info = {
"name": "UE Shader Map Setups",
"author": "Anime Nyan",
"version": (1, 0, 2),
"blender": (2, 92, 0),
"location": "TO BE ADDED",
"description": "",
"warning": "",
"wiki_url": "https://github.com/AnimNyan/UEShaderScript/wiki",
"category": "Material",
"tracker_url": "https://github.com/AnimNyan/UEShaderScript"
}
"""
Version': '1.0.2' written by Anime Nyan
Adds two panels one in the Shader Editor View to save different preset shader maps and one in the 3D View to load shader maps
"""
def register():
save_shader_map.register()
load_shader_map.register()
try:
save_shader_map.import_default_json()
except Exception as e:
print("import_default_json() exception because blender is not ready yet. :", e)
def unregister():
save_shader_map.unregister()
load_shader_map.unregister()
print("(*) UE Shader Script add-on loaded")
I also know that my add on works with the Visual Studio code Blender Plugin when I use Ctrl + P > Blender Start, but think that might start Blender differently.
As a precaution I have also added a pastebin of my whole load_shader_map.py file: https://pastebin.com/Xx18vrKz and save_shader_map.py file:https://pastebin.com/grfCCQSq however I am aware they are extremely long, only the top and perhaps the bottom of registering the classes is important.