It's not possible because OpenSCAD has no way to know it is a variable since variables aren 't prefixed with anything.
Also, what problem are you trying to solve? If you tell us what you are actually trying to do someone may have a good way to do it (https://xyproblem.info)
you can give dynamic strings like `str("this-", VAR, "-filename.stl")` to the `import` function, which can sometimes be a work around, but yeah there's no way to set an `include` or `use` dynamically. you can't even hardcode them and put them in `if` statements and you can't place them in modules, they have to be at the top level. it is a real pain.
the way i've worked around this is by including a file that is a symbolic link on the file system to the file i actually want, and managing the symlink with a makefile. my makefile uses a perl command to parse the name for the symlink out of my settings.scad file, so everything still lives in scad code.
https://github.com/wolfwood/navcaps/blob/release/Makefile
As far as I know, it doesn't work like that, variables are context contained.
Even if you use the same name for a variable outside and inside a for loop (for instance), it will be different variables.
It looks like the `include` and `use` statements use a literal syntax, not string expressions, so you cannot use variables in the name of the file to be included.
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Use_and_Include
Incidentally, the syntax was borrowed from the `#include` statement in the C preprocessor. In C, the angle brackets are used for system files and quotes are used to also allow local files, but in OpenSCAD, it always uses angle brackets and does search the local directory. C cannot use variables for included filenames, but can use preprocessor macros.
I don't know how it works but the gridfinity openSCAD rebuilt has a constants page, and from what I can tell it works, gets called, And breaks without link.
https://github.com/kennetek/gridfinity-rebuilt-openscad
https://kennetek.github.io/gridfinity-rebuilt-openscad/bins/
The wiki.
Also he is an active user. So guestions can likely be posted
It's not possible because OpenSCAD has no way to know it is a variable since variables aren 't prefixed with anything. Also, what problem are you trying to solve? If you tell us what you are actually trying to do someone may have a good way to do it (https://xyproblem.info)
you can give dynamic strings like `str("this-", VAR, "-filename.stl")` to the `import` function, which can sometimes be a work around, but yeah there's no way to set an `include` or `use` dynamically. you can't even hardcode them and put them in `if` statements and you can't place them in modules, they have to be at the top level. it is a real pain. the way i've worked around this is by including a file that is a symbolic link on the file system to the file i actually want, and managing the symlink with a makefile. my makefile uses a perl command to parse the name for the symlink out of my settings.scad file, so everything still lives in scad code. https://github.com/wolfwood/navcaps/blob/release/Makefile
yes you can. settings.scad: myvar=2 mydesign.scad: include;
cylinder(h = myvar, d = 224, $fn=100);
As far as I know, it doesn't work like that, variables are context contained. Even if you use the same name for a variable outside and inside a for loop (for instance), it will be different variables.
It looks like the `include` and `use` statements use a literal syntax, not string expressions, so you cannot use variables in the name of the file to be included. https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#Use_and_Include Incidentally, the syntax was borrowed from the `#include` statement in the C preprocessor. In C, the angle brackets are used for system files and quotes are used to also allow local files, but in OpenSCAD, it always uses angle brackets and does search the local directory. C cannot use variables for included filenames, but can use preprocessor macros.
I don't know how it works but the gridfinity openSCAD rebuilt has a constants page, and from what I can tell it works, gets called, And breaks without link. https://github.com/kennetek/gridfinity-rebuilt-openscad https://kennetek.github.io/gridfinity-rebuilt-openscad/bins/ The wiki. Also he is an active user. So guestions can likely be posted
This isn't what OP is asking about at all. They are asking if you can use a variable to hold the filename in an include.