Thank you guys for all the pointers in the right direction. I adjusted my original code to search for customized path first and then, in case nothing is found there, fall back to the default location (os environment).
def init_config(self):
self.fp_path = None
# check modified paths
settings = pcbnew.SETTINGS_MANAGER.GetUserSettingsPath()
with open(settings+'/kicad_common.json', 'r') as f:
data = json.load(f)
if not (data["environment"]["vars"] is None) and "KICAD6_FOOTPRINT_DIR" in data["environment"]["vars"]:
self.fp_path = data["environment"]["vars"]["KICAD6_FOOTPRINT_DIR"]
# check default paths
if self.fp_path is None:
self.fp_path = os.getenv("KICAD6_FOOTPRINT_DIR", default=None)
# no library found
if self.fp_path is None:
wx.LogError("Footprint library not found - Make sure the KiCad paths are properly configured.")
I have a feeling that there’s a better way to access the common settings than reading the file and drilling down the json tree, using the following member function (see API docs ):