Changing the present working directory a Kicad Plugin

I’m looking to modify KiCAD-EasyEDA-Parts to use relative paths for 3D models rather than absolute paths all while remaining in the project directory.

RIght now, using the EasyEDA Parts plugin and easyeda2kicad with the --project-relative parameter, the footprints have the path to the 3D models hard coded to have ${KIPRJMOD} prepended to the set output path (e.g. ${KIPRJMOD}/home/user/Documents/KicadProj/libs/easyeda ).

I’d like it to change to the Kicad project directory and then importing the component using easyeda2kicad. Within the context of a plugin, am I unable to change the current working directory with os.chdir(path) ? The plugin seems to keep getting hung up on this. and not proceeding with the rest of the python code, which does work if I omit the line changing the directory.

I’m not sure why that does not work for you, I tried it on my installation and it worked. Your issue is likely somewhere else.

That sounds like a bug but not sure how changing working directory is supposed to help.

Can you confirm what exactly it was that you did and specifically how it “worked”? Are you using KiCAD-EasyEDA-Parts or easyeda2kicad in the terminal? Are you checking the paths in the footprint itself for the 3D models and verifying that it is only prepending ${KIPRJMOD} and then the subsequent directories? e.g. ${KIPRJMOD}/libs/easyeda and not ${KIPRJMOD}/home/user/Documents/KicadProj/libs/easyeda

My issues is specifically using the KiCAD-EasyEDA-Parts plugin and not using easyeda2kicad in the terminal where I can manually navigate to the project directory. It’s the fact that within the context of using the Kicad Plugin, I (at this time) cannot specify/change the working directory and, by default, it starts at the user’s home directory (/home/username/) rather than in the KiCAD project directory. So I have to provide an absolute path because otherwise, using the command easyeda2kicad --full --lcsc_id=C2040 --output ./libs/easyeda --project-relative creates the files at /home/username/libs/easyeda. Where I do not want them to be. I want them to be in the project directory.

The reason I want to do this at all is because, if I ever clone an existing project that used the plugin to generate the symbol/footprint/3D model files, stuff breaks. The 3D models are always broken because the footprints use absolute paths for the original project to the 3D models, not the cloned project. Which would resolved if it used a KiCAD project relative paths.

Note: I am not using the existing plugin and have already modified it to use the --project-relative option so you can’t have tested what I was described.

Currently, the plugin uses absolute paths without the --project-relative option for easyeda2kicad under the hood, resulting in an absolute path in the 3D model path for the footprint as well.

So again, I am not looking for advice on how to make KiCAD-EasyEDA-Parts or easyeda2kicad work. I am only asking how, if I even can, change the working directory when running a plugin’s python code. If I can do that, then I know that I am otherwise doing will work how I want it to.

Sorry, I wasn’t clear enough, I tried doing os.chdir(path) in kicad’s scripting console, which is exact same environment as kicad’s plugins and it worked there, verified by os.getcwd().

Looking at the source of the KiCAD-EasyEDA-Parts it likely has issues that are not related to what working directory it uses. I suggest you add more logging to debug what is actually going on in your modified code and see which line causes the program to get stuck.