GH
gene heskett
Thu, Jun 26, 2025 9:23 PM
On 6/26/25 12:58, Leonard Martin Struttmann via Discuss wrote:
That worked, thank you. Is this a required rule?
In this case, yes. The OpenSCAD docs say "use <filename> is allowed only
at the top level of a file."
So is "include" an alias for "use"? It seems to act like it is. except
"use" is a show stopper error
...and BOLS2 color.scad contains a use statement:
color.scad:use <builtins.scad>
Which assumes the default library path is correct. So my use of the full
path should not be required?
It apparently is good, removing the full path still works. Thank you.
Cheers, Gene Heskett, CET.
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
On 6/26/25 12:58, Leonard Martin Struttmann via Discuss wrote:
> *That worked, thank you. Is this a required rule?*
>
>
> In this case, yes. The OpenSCAD docs say "use <*filename*> is allowed only
> at the top level of a file."
So is "include" an alias for "use"? It seems to act like it is. except
"use" is a show stopper error
> ...and BOLS2 color.scad contains a use statement:
>
>
> color.scad:use <builtins.scad>
Which assumes the default library path is correct. So my use of the full
path should not be required?
It apparently is good, removing the full path still works. Thank you.
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
Cheers, Gene Heskett, CET.
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
- Louis D. Brandeis
AM
Adrian Mariano
Thu, Jun 26, 2025 9:40 PM
The "use" and "include" statements are different. The intention of "use"
is to import a library while somewhat encapsulating it from the rest of the
code. You're supposed to be able to run the file stand-alone to generate
examples, or run use it as a library. Unfortunately, due to a bug in
OpenSCAD, if you use "use" then anytime you call a function in the used
file it runs every command that appears at the top level in the file. This
was making some things in BOSL2 1000x slower, so we abandoned "use". The
"include" statement just directly includes the contents of the file, as if
they appeared right there in the code.
On Thu, Jun 26, 2025 at 5:23 PM gene heskett via Discuss <
discuss@lists.openscad.org> wrote:
On 6/26/25 12:58, Leonard Martin Struttmann via Discuss wrote:
That worked, thank you. Is this a required rule?
In this case, yes. The OpenSCAD docs say "use <filename> is allowed
at the top level of a file."
So is "include" an alias for "use"? It seems to act like it is. except
"use" is a show stopper error
...and BOLS2 color.scad contains a use statement:
color.scad:use <builtins.scad>
Which assumes the default library path is correct. So my use of the full
path should not be required?
It apparently is good, removing the full path still works. Thank you.
Cheers, Gene Heskett, CET.
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
The "use" and "include" statements are different. The intention of "use"
is to import a library while somewhat encapsulating it from the rest of the
code. You're supposed to be able to run the file stand-alone to generate
examples, or run use it as a library. Unfortunately, due to a bug in
OpenSCAD, if you use "use" then anytime you call a function in the used
file it runs every command that appears at the top level in the file. This
was making some things in BOSL2 1000x slower, so we abandoned "use". The
"include" statement just directly includes the contents of the file, as if
they appeared right there in the code.
On Thu, Jun 26, 2025 at 5:23 PM gene heskett via Discuss <
discuss@lists.openscad.org> wrote:
> On 6/26/25 12:58, Leonard Martin Struttmann via Discuss wrote:
> > *That worked, thank you. Is this a required rule?*
> >
> >
> > In this case, yes. The OpenSCAD docs say "use <*filename*> is allowed
> only
> > at the top level of a file."
> So is "include" an alias for "use"? It seems to act like it is. except
> "use" is a show stopper error
> > ...and BOLS2 color.scad contains a use statement:
> >
> >
> > color.scad:use <builtins.scad>
>
> Which assumes the default library path is correct. So my use of the full
> path should not be required?
>
> It apparently is good, removing the full path still works. Thank you.
>
> > OpenSCAD mailing list
> > To unsubscribe send an email to discuss-leave@lists.openscad.org
>
> Cheers, Gene Heskett, CET.
> --
> "There are four boxes to be used in defense of liberty:
> soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author, 1940)
> If we desire respect for the law, we must first make the law respectable.
> - Louis D. Brandeis
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
GH
gene heskett
Thu, Jun 26, 2025 10:13 PM
On 6/26/25 13:11, Jordan Brown via Discuss wrote:
On 6/26/2025 9:37 AM, gene heskett via Discuss wrote:
On 6/26/25 11:04, Leonard Martin Struttmann via Discuss wrote:
Try moving the include statements above (outside) of the module
definition.
That worked, thank you. Is this a required rule?
Mostly, yes.
The include directive copies the specified file into your program,
almost exactly as if you replaced the include with the text of the
file. (There's a little bit of magic to allow overriding variables in
the same scope.)
Usually, you want a library to be at the top level. Some constructs may
require it - in this case, a "use" that BOSL2 uses internally.
That's not the only problem.
Here's your original text. I've reformatted it for readability, but
changed only the whitespace, not anything that actually changes the
semantics.
module test() //fixed, still works
{
include </home/gene/.local/share/OpenSCAD/libraries/BOSL2/std.scad>
include </home/gene/.local/share/OpenSCAD/libraries/BOSL2/threading.scad>
difference() {
cylinder(h=50, d=16, $fn=150);
translate([0,0,1.5])
cylinder(h=32.5, d=12);
translate([0,0,34])
threaded_rod(d=12, l=16, pitch=2, internal=false, bevel=0.5); }
}
test();
Reformatting like this makes a couple of things more obvious.
First is the semicolon after "module test()". That makes the module be
empty. The stuff in braces is some non-module stuff that's in what the
manual calls an "anonymous scope" which mostly isn't a scope at all. An
anonymous scope mostly isn't a scope at all, but it's enough to make
"use" fail.
Second is that the difference() has only one child,
Actually two, first expands to clear the threads at the bottom of the
central hole,
And the second is the threaded_rod threading the top of the hole.
so is kind of
boring. I think it wants an open brace immediately after "difference()"
and a close brace after the call to threaded_rod().
done.
This likely would not print well because there is no visible
compensation for the expansion caused by the size of the nozzle,
typically .4mm.
In my personal use where I am fitting a 2 start plastic printed nut pair
of halves, so I reduce the image of the maple screw that started as a
27" 2x2 that is just short of 48mm in diameter once carved on my 6040 4
axis mill, I use the same bolt code made nominally .25mm small to
preview the bolt, and make the same bolt code when used as the
difference to make the nuts, is made .25mm bigger when making the nuts.
So the assembly has about .1mm backlash yet turns freely when the screw
is painted with pure carnaba wax. With about 13 teeth engaged, that
maple screw might as well be 4340 steel. A buttress thread is only 4mm
tall, and the pitch is 12mm per turn of the vice handle. So if I were to
make this, and assuming a commercially available bolt of nominally 12mm
diameter, I would measure its actual OD and expand the clearance
cylinder in the bottom by .5mm, and the diameter of the bolt by .45mm to
assure adequate clearance. Assuming of course that the printer is well
calibrated. This sort of thinking will get a usable part for the OP at
least 1 iteration quicker.
So, going back to your original question, yes, libraries usually want
"include" or "use" at the top level.
"use" does not work here.
There may be special cases where "include" might be useful at other points.
For instance, if you have a file that has a bunch of numbers separated
by commas, you could put it in an OpenSCAD array like so:
array = [
include <datafile.txt>
];
(Note: this will not process general CSV. The file must be valid
OpenSCAD syntax, which means commas between the elements, quotes around
strings, and so on.)
But these special cases are very much the exception.
For super extra fun, try this program. Hint: don't use "include" as a
variable name.
include = 2;
something = 5;
if (include < 3 && something > 4) {
echo("surprise!");
}
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Thank you.
Cheers, Gene Heskett, CET.
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
On 6/26/25 13:11, Jordan Brown via Discuss wrote:
> On 6/26/2025 9:37 AM, gene heskett via Discuss wrote:
>> On 6/26/25 11:04, Leonard Martin Struttmann via Discuss wrote:
>>> Try moving the include statements above (outside) of the module
>>> definition.
>> That worked, thank you. Is this a required rule?
> Mostly, yes.
>
> The include directive copies the specified file into your program,
> almost exactly as if you replaced the include with the text of the
> file. (There's a little bit of magic to allow overriding variables in
> the same scope.)
>
> Usually, you want a library to be at the top level. Some constructs may
> require it - in this case, a "use" that BOSL2 uses internally.
>
> That's not the only problem.
>
> Here's your original text. I've reformatted it for readability, but
> changed only the whitespace, not anything that actually changes the
> semantics.
>
> module test() //fixed, still works
> {
> include </home/gene/.local/share/OpenSCAD/libraries/BOSL2/std.scad>
> include </home/gene/.local/share/OpenSCAD/libraries/BOSL2/threading.scad>
> difference() {
> cylinder(h=50, d=16, $fn=150);
> translate([0,0,1.5])
> cylinder(h=32.5, d=12);
> translate([0,0,34])
> threaded_rod(d=12, l=16, pitch=2, internal=false, bevel=0.5); }
> }
> test();
>
> Reformatting like this makes a couple of things more obvious.
>
> First is the semicolon after "module test()". That makes the module be
> empty. The stuff in braces is some non-module stuff that's in what the
> manual calls an "anonymous scope" which mostly isn't a scope at all. An
> anonymous scope mostly isn't a scope at all, but it's enough to make
> "use" fail.
>
> Second is that the difference() has only one child,
Actually two, first expands to clear the threads at the bottom of the
central hole,
And the second is the threaded_rod threading the top of the hole.
> so is kind of
> boring. I think it wants an open brace immediately after "difference()"
> and a close brace after the call to threaded_rod().
done.
This likely would not print well because there is no visible
compensation for the expansion caused by the size of the nozzle,
typically .4mm.
In my personal use where I am fitting a 2 start plastic printed nut pair
of halves, so I reduce the image of the maple screw that started as a
27" 2x2 that is just short of 48mm in diameter once carved on my 6040 4
axis mill, I use the same bolt code made nominally .25mm small to
preview the bolt, and make the same bolt code when used as the
difference to make the nuts, is made .25mm bigger when making the nuts.
So the assembly has about .1mm backlash yet turns freely when the screw
is painted with pure carnaba wax. With about 13 teeth engaged, that
maple screw might as well be 4340 steel. A buttress thread is only 4mm
tall, and the pitch is 12mm per turn of the vice handle. So if I were to
make this, and assuming a commercially available bolt of nominally 12mm
diameter, I would measure its actual OD and expand the clearance
cylinder in the bottom by .5mm, and the diameter of the bolt by .45mm to
assure adequate clearance. Assuming of course that the printer is well
calibrated. This sort of thinking will get a usable part for the OP at
least 1 iteration quicker.
> So, going back to your original question, yes, libraries usually want
> "include" or "use" at the top level.
"use" does not work here.
> There may be special cases where "include" might be useful at other points.
>
> For instance, if you have a file that has a bunch of numbers separated
> by commas, you could put it in an OpenSCAD array like so:
>
> array = [
> include <datafile.txt>
> ];
>
> (Note: this will *not* process general CSV. The file must be valid
> OpenSCAD syntax, which means commas between the elements, quotes around
> strings, and so on.)
>
> But these special cases are very much the exception.
>
> For super extra fun, try this program. Hint: don't use "include" as a
> variable name.
>
> include = 2;
> something = 5;
> if (include < 3 && something > 4) {
> echo("surprise!");
> }
>
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
Thank you.
Cheers, Gene Heskett, CET.
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
- Louis D. Brandeis
JB
Jordan Brown
Fri, Jun 27, 2025 5:24 PM
On 6/26/2025 3:13 PM, gene heskett via Discuss wrote:
Second is that the difference() has only one child,
Ah, I see that you fixed that in an iteration after the one I quoted.
Sorry.
So, going back to your original question, yes, libraries usually want
"include" or "use" at the top level.
"use" does not work here.
Some libraries want to be "included", while others want to be "used".
BOSL2 wants to be "included".
On 6/26/2025 3:13 PM, gene heskett via Discuss wrote:
>> Second is that the difference() has only one child,
> Actually two,
>
Ah, I see that you fixed that in an iteration after the one I quoted.
Sorry.
>> So, going back to your original question, yes, libraries usually want
>> "include" or "use" at the top level.
> "use" does not work here.
Some libraries want to be "included", while others want to be "used".
BOSL2 wants to be "included".
GH
gene heskett
Fri, Jun 27, 2025 6:58 PM
On 6/27/25 13:25, Jordan Brown via Discuss wrote:
On 6/26/2025 3:13 PM, gene heskett via Discuss wrote:
Second is that the difference() has only one child,
Ah, I see that you fixed that in an iteration after the one I quoted.
Sorry.
NP. While I was pointing out that the 2 subtraction children existed in
the OP's first post. That snippet did not constrain the scope of the
difference so I added a pair of {} to do so. Makes, in this case, no
difference in the final result as there is not anything that s/b
excluded from the difference beyond the scope of the difference.
So, going back to your original question, yes, libraries usually want
"include" or "use" at the top level.
"use" does not work here.
Some libraries want to be "included", while others want to be "used".
BOSL2 wants to be "included".
A difference I don't see defined. It may be, but my hardcopy printout is
now 4 years old. I suspect that today it would be a dozen+ pages longer. ;)
Thanks Jordan.
Cheers, Gene Heskett, CET.
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
On 6/27/25 13:25, Jordan Brown via Discuss wrote:
> On 6/26/2025 3:13 PM, gene heskett via Discuss wrote:
>>> Second is that the difference() has only one child,
>> Actually two,
>>
> Ah, I see that you fixed that in an iteration after the one I quoted.
> Sorry.
NP. While I was pointing out that the 2 subtraction children existed in
the OP's first post. That snippet did not constrain the scope of the
difference so I added a pair of {} to do so. Makes, in this case, no
difference in the final result as there is not anything that s/b
excluded from the difference beyond the scope of the difference.
>>> So, going back to your original question, yes, libraries usually want
>>> "include" or "use" at the top level.
>> "use" does not work here.
> Some libraries want to be "included", while others want to be "used".
> BOSL2 wants to be "included".
A difference I don't see defined. It may be, but my hardcopy printout is
now 4 years old. I suspect that today it would be a dozen+ pages longer. ;)
Thanks Jordan.
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
Cheers, Gene Heskett, CET.
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author, 1940)
If we desire respect for the law, we must first make the law respectable.
- Louis D. Brandeis
JB
Jordan Brown
Fri, Jun 27, 2025 8:13 PM
On 6/27/2025 11:58 AM, gene heskett via Discuss wrote:
Some libraries want to be "included", while others want to be "used".
BOSL2 wants to be "included".
A difference I don't see defined. It may be, but my hardcopy printout
is now 4 years old. I suspect that today it would be a dozen+ pages
longer. ;)
On 6/27/2025 11:58 AM, gene heskett via Discuss wrote:
>> Some libraries want to be "included", while others want to be "used".
>> BOSL2 wants to be "included".
> A difference I don't see defined. It may be, but my hardcopy printout
> is now 4 years old. I suspect that today it would be a dozen+ pages
> longer. ;)
The difference between the two is documented at
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Include_Statement
I don't immediately see anything in the BOSL2 documentation that
discusses the distinction, but the examples all use "include".
FH
Father Horton
Fri, Jun 27, 2025 8:31 PM
I don't know why there should be a difference with BOSL2, but just for fun,
I opened an existing file that works fine, changed the "include" to "use",
and got errors.
On Fri, Jun 27, 2025 at 3:14 PM Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:
On 6/27/2025 11:58 AM, gene heskett via Discuss wrote:
Some libraries want to be "included", while others want to be "used".
BOSL2 wants to be "included".
A difference I don't see defined. It may be, but my hardcopy printout is
now 4 years old. I suspect that today it would be a dozen+ pages longer. ;)
The difference between the two is documented at
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Include_Statement
I don't immediately see anything in the BOSL2 documentation that discusses
the distinction, but the examples all use "include".
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
I don't know why there should be a difference with BOSL2, but just for fun,
I opened an existing file that works fine, changed the "include" to "use",
and got errors.
On Fri, Jun 27, 2025 at 3:14 PM Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:
> On 6/27/2025 11:58 AM, gene heskett via Discuss wrote:
>
> Some libraries want to be "included", while others want to be "used".
> BOSL2 wants to be "included".
>
> A difference I don't see defined. It may be, but my hardcopy printout is
> now 4 years old. I suspect that today it would be a dozen+ pages longer. ;)
>
>
> The difference between the two is documented at
>
> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Include_Statement
>
>
> I don't immediately see anything in the BOSL2 documentation that discusses
> the distinction, but the examples all use "include".
>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
AM
Adrian Mariano
Fri, Jun 27, 2025 9:12 PM
BOSL2 defines global variables at the top level that are then referenced by
other files than the one where they are defined. This works with include
but does not work with use.
On Fri, Jun 27, 2025 at 4:32 PM Father Horton via Discuss <
discuss@lists.openscad.org> wrote:
I don't know why there should be a difference with BOSL2, but just for
fun, I opened an existing file that works fine, changed the "include" to
"use", and got errors.
On Fri, Jun 27, 2025 at 3:14 PM Jordan Brown via Discuss <
discuss@lists.openscad.org> wrote:
On 6/27/2025 11:58 AM, gene heskett via Discuss wrote:
Some libraries want to be "included", while others want to be "used".
BOSL2 wants to be "included".
A difference I don't see defined. It may be, but my hardcopy printout is
now 4 years old. I suspect that today it would be a dozen+ pages longer. ;)
The difference between the two is documented at
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Include_Statement
I don't immediately see anything in the BOSL2 documentation that
discusses the distinction, but the examples all use "include".
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
BOSL2 defines global variables at the top level that are then referenced by
other files than the one where they are defined. This works with include
but does not work with use.
On Fri, Jun 27, 2025 at 4:32 PM Father Horton via Discuss <
discuss@lists.openscad.org> wrote:
> I don't know why there should be a difference with BOSL2, but just for
> fun, I opened an existing file that works fine, changed the "include" to
> "use", and got errors.
>
> On Fri, Jun 27, 2025 at 3:14 PM Jordan Brown via Discuss <
> discuss@lists.openscad.org> wrote:
>
>> On 6/27/2025 11:58 AM, gene heskett via Discuss wrote:
>>
>> Some libraries want to be "included", while others want to be "used".
>> BOSL2 wants to be "included".
>>
>> A difference I don't see defined. It may be, but my hardcopy printout is
>> now 4 years old. I suspect that today it would be a dozen+ pages longer. ;)
>>
>>
>> The difference between the two is documented at
>>
>> https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Include_Statement
>>
>>
>> I don't immediately see anything in the BOSL2 documentation that
>> discusses the distinction, but the examples all use "include".
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> To unsubscribe send an email to discuss-leave@lists.openscad.org
>>
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>
FH
Father Horton
Fri, Jun 27, 2025 11:15 PM
I guess that’s implicit in what it says, but an explicit statement that
global variable assignments don’t happen with a “use” would be handy.
I guess that’s implicit in what it says, but an explicit statement that
global variable assignments don’t happen with a “use” would be handy.
AM
Adrian Mariano
Fri, Jun 27, 2025 11:23 PM
It seems like the text about "use" is fairly explicit, when it says that if
A uses B then neither A nor B can see global variables defined in the other
file.
It doesn't mean global variable assignments "don't happen" because if B
makes global variable assignments they do get run---in fact they get
(re)run every time you invoke a function defined in B. But those global
definitions are only global to B, not global to the whole program.
On Fri, Jun 27, 2025 at 7:15 PM Father Horton via Discuss <
discuss@lists.openscad.org> wrote:
I guess that’s implicit in what it says, but an explicit statement that
global variable assignments don’t happen with a “use” would be handy.
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
It seems like the text about "use" is fairly explicit, when it says that if
A uses B then neither A nor B can see global variables defined in the other
file.
It doesn't mean global variable assignments "don't happen" because if B
makes global variable assignments they do get run---in fact they get
(re)run every time you invoke a function defined in B. But those global
definitions are only global to B, not global to the whole program.
On Fri, Jun 27, 2025 at 7:15 PM Father Horton via Discuss <
discuss@lists.openscad.org> wrote:
> I guess that’s implicit in what it says, but an explicit statement that
> global variable assignments don’t happen with a “use” would be handy.
> _______________________________________________
> OpenSCAD mailing list
> To unsubscribe send an email to discuss-leave@lists.openscad.org
>