[Solved] Global Envrionment variable based on a project variable

Hi,

I want to set a global variable based on KIPRJMOD, but I seem to be unable to do it. If I go to Preferences / Configure Path and create a new variable that uses KIPRJMOD as it’s base, that new global variable doesn’t work.

Here’s my setup and a bit more of background:

\Big Project
\Subproject 1
\Subproject 2
\Common Libraries
library1.lib

In Subproject 1, KIPRJMOD points to /Big Project/Subproject 1. I can add a project specific library using the relative path ${KIPRJMOD}/../Common Libraries\librar1.lib. Cool. Same thing for Subproject N and everything works

I thought, what would be even better, as all my projects are going to follow the same pattern, I thought, why not create a global environment variable LIB_PATH that uses whatever the project folder is for that subproject KIPRJMOD is. But if I then add a project-specific library using ${LIB_PATH}\library1.lib, Kicad 5 can’t find it. So at this point, I would say that you can’t define global variables based on project variables.

Is that true?

PS: there is a reason why even though using ${KIPRJMOD}…\whatever works, I would prefer to use the global variable. It’s a bit convoluted and I don’t want to fill the post with the explanation, but I just wanted to be clear why I want it that way.

I think combining environment variables would work in the OS level, but KiCad doesn’t handle that. See my document https://docs.google.com/document/d/1Rq8i2Ay7qpGpffaj-AQmE-Xp88ikHhgyt0Ygpi8717o/edit?usp=sharing for some instructions about how to use environment variables from outside KiCad. You can define and combine them in the way your OS allows.

On the other hand I wouldn’t recommend such a complex setup even though it might feel good at first sight.

Well, I know that you can combine global variables. My previous setup had a global variable pointing to my libraries folder, and another global variable pointing to a folder inside it where my 3D models live, i.e.:

\My Library
\My Library.pretty
\3D models

${Lib_Path} = C:\My Libraries\My Library.pretty
${3D_Models_Path} = ${Lib_Path}\3D Models

And that worked.

In any case, thanks for your quick reply. I wanted to go this route because it’s going to be shared project, and I don’t want to add paths to the system in order for it to work. I can live with project-specific variables, I will go that route then.

Do you mean inside KiCad? I have a vague memory about trying that once but not succeeding. I may be wrong. In any case there would be a logical problem if KiCad tried to resolve such variables. What would happen if you had

${A} = ${B}
${B} = ${A}

That can work in the OS shell because it goes line by line in order and can e.g. replace the non-defined with empty string. For KiCad which doesn’t guarantee order it would be undetermined and could even lead to infinite loop or would require much code and more UI dialogs. In my opinion that’s a good enough reason to not allow such thing inside KiCad. But again, I may be wrong.

Ok, I got it!

You are right. It doesn’t work, probably because of the reason you mentioned of circular references. If you try to add a library either in eeschema or pcbnew with a symbol that is defined with another symbol, KiCad refuses to translate it and fails.

But as I said, I got it working before, and that’s where the confusion comes from. There is a situation where it works: you can define a global path var with a reference to another var, and that will work as a 3D model location path. I used to have a variable pointing to my library, and another variable pointing to the 3D model folder of that library, and it was working, and I assumed that it will work everywhere else, but the opposite seems to be true, it ONLY works there (or at least, it doesn’t work as a project-specific library path).

So, to sum it all:

You have an environmental variable A = c:\ and B = ${A}\New folder

No, you can’t define a library path using B, an environment variable defined by another environment variable.

But yes, you can define a 3D model path using B, an environment variable defined by another environment variable and it will translate correctly when looking for 3D parts.

I think that closes the issue. Thanks for your help!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.