discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Fwd: Re: start a module from a variabel

NH
nop head
Sat, Oct 23, 2021 9:03 AM

The module that makes the box has an echo statement that shows the internal
dimensions.

ECHO: "Box:", 133, 89, 150

This is because they are usually complicated expressions to fit the
internal components, so it is not obvious what they are. When the box is
small enough I use 3D printed panels. When it is too big for my printer I
use CNC cut DiBond panels with printed bezels and corner profiles. They can
be printed in arbitrarily many pieces and solvent welded together. So I can
make enclosures up to the capacity of my CNC milling machine. I also have a
simpler box in my library that is just sheets and brackets.
[image: image.png]

That module also echos its internal volume because I made a double walled
filament dryer and needed to estimate the volume of insulations that I
needed. So I subtracted the volume of the inner box. I stuff the gap with
cotton wool, which is a nice to handle insulator.
[image: bbox_assembly.png]

On Sat, 23 Oct 2021 at 08:57, terrypingm@gmail.com terrypingm@gmail.com
wrote:

“ When I do F5 OpenSCAD tells me my box is 133 x 89 x 150“

Please excuse this elementary side question:
Do you mean that’s what you visually measure from the axes markers? Or is
it something more explicit?
Terry

--
Terry

On 22 Oct 2021, at 22:52, nop head nop.head@gmail.com wrote:

When I do F5 OpenSCAD tells me my box is 133 x 89 x 150


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

The module that makes the box has an echo statement that shows the internal dimensions. ECHO: "Box:", 133, 89, 150 This is because they are usually complicated expressions to fit the internal components, so it is not obvious what they are. When the box is small enough I use 3D printed panels. When it is too big for my printer I use CNC cut DiBond panels with printed bezels and corner profiles. They can be printed in arbitrarily many pieces and solvent welded together. So I can make enclosures up to the capacity of my CNC milling machine. I also have a simpler box in my library that is just sheets and brackets. [image: image.png] That module also echos its internal volume because I made a double walled filament dryer and needed to estimate the volume of insulations that I needed. So I subtracted the volume of the inner box. I stuff the gap with cotton wool, which is a nice to handle insulator. [image: bbox_assembly.png] On Sat, 23 Oct 2021 at 08:57, terrypingm@gmail.com <terrypingm@gmail.com> wrote: > “ When I do F5 OpenSCAD tells me my box is 133 x 89 x 150“ > > Please excuse this elementary side question: > Do you mean that’s what you visually measure from the axes markers? Or is > it something more explicit? > Terry > > -- > Terry > > > On 22 Oct 2021, at 22:52, nop head <nop.head@gmail.com> wrote: > > > > When I do F5 OpenSCAD tells me my box is 133 x 89 x 150 > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
TP
Torsten Paul
Sat, Oct 23, 2021 6:01 PM

On 22.10.21 21:25, Patrick Callahan wrote:

I am thinking about where to put various kinds of data
in an OpenSCAD project.

It also should soon(-ish) be possible to import data via
JSON files.

See https://github.com/openscad/openscad/pull/3891

Example with JSON file:

{
"number": 2,
"float": 3.5e-10,
"bool": true,
"string": "hallo world!",
"array_number": [ 0, 1, 2, 3, 5 ],
"array-string": [ "one", "two", "three" ],
"array-mixed": [ "one", 1, false ],
"object": {
"name": "The object name",
"nested": {
"value": 42
},
"number": 4
}
}

Usage:

j = import("scad-data.json");

echo(j.string); // ECHO: "hallo world!"
echo(j.array_number); // ECHO: [0, 1, 2, 3, 5]
echo(j["array-string"]); // ECHO: ["one", "two", "three"]
echo(j.object.name); // ECHO: "The object name"
echo(j.object.nested.value); // ECHO: 42

ciao,
Torsten.

On 22.10.21 21:25, Patrick Callahan wrote: > I am thinking about where to put various kinds of data > in an OpenSCAD project. It also should soon(-ish) be possible to import data via JSON files. See https://github.com/openscad/openscad/pull/3891 Example with JSON file: { "number": 2, "float": 3.5e-10, "bool": true, "string": "hallo world!", "array_number": [ 0, 1, 2, 3, 5 ], "array-string": [ "one", "two", "three" ], "array-mixed": [ "one", 1, false ], "object": { "name": "The object name", "nested": { "value": 42 }, "number": 4 } } Usage: j = import("scad-data.json"); echo(j.string); // ECHO: "hallo world!" echo(j.array_number); // ECHO: [0, 1, 2, 3, 5] echo(j["array-string"]); // ECHO: ["one", "two", "three"] echo(j.object.name); // ECHO: "The object name" echo(j.object.nested.value); // ECHO: 42 ciao, Torsten.
LM
Leonard Martin Struttmann
Sat, Oct 23, 2021 9:45 PM

As for avoiding frameworks becoming more onerous than the problem, that's
something I'd prefer to avoid.  I know from experience that it's easy to
let the tail wag the dog.

*I'm not so much looking for a library or method that solves all problems,
as seeking a small set of strategies or guidelines for creating modules,
functions, and variables, then putting them in separate files that play
nicely together across a larger project. *

Patrick,

I, too, felt this way when I first started more complex projects. I didn't
want to learn someone else's framework which would probably be much more
complicated than I needed.

In the end, I came up with a set of coding practices with a small number of
helper utilities that help me keep things organized.

My most important practices are:

1, Each part is in its own file.
2. Part files are never accessed with include<>.  They are accessed with
use<>.  This avoids polluting my namespace.
3. If I need data from a part, I publish that data by defining a function
in the part file.  This function usually has the same name as the part
module.
4. If multiple data items need to be published, the part function uses a
text-based table lookup to return the correct data item.

Example:

In my main assembly I can create a part and query properties of that part:

use <stepper_motor_bracket.scad>

stepper_motor_bracket( parameters... );
bracket_height = stepper_motor_bracket( "height" );
bracket_width = stepper_motor_bracket( "width" );

On Sat, Oct 23, 2021 at 1:02 PM Torsten Paul Torsten.Paul@gmx.de wrote:

On 22.10.21 21:25, Patrick Callahan wrote:

I am thinking about where to put various kinds of data
in an OpenSCAD project.

It also should soon(-ish) be possible to import data via
JSON files.

See https://github.com/openscad/openscad/pull/3891

Example with JSON file:

{
"number": 2,
"float": 3.5e-10,
"bool": true,
"string": "hallo world!",
"array_number": [ 0, 1, 2, 3, 5 ],
"array-string": [ "one", "two", "three" ],
"array-mixed": [ "one", 1, false ],
"object": {
"name": "The object name",
"nested": {
"value": 42
},
"number": 4
}
}

Usage:

j = import("scad-data.json");

echo(j.string); // ECHO: "hallo world!"
echo(j.array_number); // ECHO: [0, 1, 2, 3, 5]
echo(j["array-string"]); // ECHO: ["one", "two", "three"]
echo(j.object.name); // ECHO: "The object name"
echo(j.object.nested.value); // ECHO: 42

ciao,
Torsten.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

*As for avoiding frameworks becoming more onerous than the problem, that's something I'd prefer to avoid. I know from experience that it's easy to let the tail wag the dog.* *I'm not so much looking for a library or method that solves all problems, as seeking a small set of strategies or guidelines for creating modules, functions, and variables, then putting them in separate files that play nicely together across a larger project. * Patrick, I, too, felt this way when I first started more complex projects. I didn't want to learn someone else's framework which would probably be much more complicated than I needed. In the end, I came up with a set of coding practices with a small number of helper utilities that help me keep things organized. My most important practices are: 1, Each part is in its own file. 2. Part files are never accessed with include<>. They are accessed with use<>. This avoids polluting my namespace. 3. If I need data from a part, I publish that data by defining a function in the part file. This function usually has the same name as the part module. 4. If multiple data items need to be published, the part function uses a text-based table lookup to return the correct data item. Example: In my main assembly I can create a part and query properties of that part: use <stepper_motor_bracket.scad> stepper_motor_bracket( parameters... ); bracket_height = stepper_motor_bracket( "height" ); bracket_width = stepper_motor_bracket( "width" ); On Sat, Oct 23, 2021 at 1:02 PM Torsten Paul <Torsten.Paul@gmx.de> wrote: > On 22.10.21 21:25, Patrick Callahan wrote: > > I am thinking about where to put various kinds of data > > in an OpenSCAD project. > > It also should soon(-ish) be possible to import data via > JSON files. > > See https://github.com/openscad/openscad/pull/3891 > > Example with JSON file: > > { > "number": 2, > "float": 3.5e-10, > "bool": true, > "string": "hallo world!", > "array_number": [ 0, 1, 2, 3, 5 ], > "array-string": [ "one", "two", "three" ], > "array-mixed": [ "one", 1, false ], > "object": { > "name": "The object name", > "nested": { > "value": 42 > }, > "number": 4 > } > } > > Usage: > > j = import("scad-data.json"); > > echo(j.string); // ECHO: "hallo world!" > echo(j.array_number); // ECHO: [0, 1, 2, 3, 5] > echo(j["array-string"]); // ECHO: ["one", "two", "three"] > echo(j.object.name); // ECHO: "The object name" > echo(j.object.nested.value); // ECHO: 42 > > ciao, > Torsten. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
RW
Ray West
Sat, Oct 23, 2021 11:59 PM

On 23/10/2021 22:45, Leonard Martin Struttmann wrote:

  1. Part files are never accessed with include<>.  They are accessed
    with use<>.  This avoids polluting my namespace.

I don't think you can put a 'use' inside a module, but you can use an
'include'.  It may be a bug.

e.g. Module fred(){

include<alibfile.scad>;

}

is ok, but

module fred(){

use<alibfile.scad>;

}

is not

Putting libraries of parts inside modules in the layout main file, say,
prevents anything in the part files polluting the layout file space, or
other part files,  but allows part values to be set, either globally, or
individually.

On 23/10/2021 22:45, Leonard Martin Struttmann wrote: > 2. Part files are never accessed with include<>.  They are accessed > with use<>.  This avoids polluting my namespace. I don't think you can put a 'use' inside a module, but you can use an 'include'.  It may be a bug. e.g. Module fred(){ include<alibfile.scad>; } is ok, but module fred(){ use<alibfile.scad>; } is not Putting libraries of parts inside modules in the layout main file, say, prevents anything in the part files polluting the layout file space, or other part files,  but allows part values to be set, either globally, or individually.
GH
Gene Heskett
Sun, Oct 24, 2021 12:18 AM

On Saturday 23 October 2021 19:59:43 Ray West wrote:

On 23/10/2021 22:45, Leonard Martin Struttmann wrote:

  1. Part files are never accessed with include<>.  They are accessed
    with use<>.  This avoids polluting my namespace.

I don't think you can put a 'use' inside a module, but you can use an
'include'.  It may be a bug.

e.g. Module fred(){

include<alibfile.scad>;

}

is ok, but

module fred(){

use<alibfile.scad>;

}

is not

Putting libraries of parts inside modules in the layout main file,
say, prevents anything in the part files polluting the layout file
space, or other part files,  but allows part values to be set, either
globally, or individually.

Let me see if I have the correct concept of the difference here.

The first example above does not execute it until you include it in s
statement such as
"translate([,0,0,0]) "modulename in alibfile(args)"

but if its a "use<alibfile.scad" you are telling it to execute it but
there's no syntax to pass the "args" so it fails. right, wrong, or so
far out its not even wrong as W. Pauli once wrote?

Cheers, Gene Heskett.

"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 Saturday 23 October 2021 19:59:43 Ray West wrote: > On 23/10/2021 22:45, Leonard Martin Struttmann wrote: > > 2. Part files are never accessed with include<>.  They are accessed > > with use<>.  This avoids polluting my namespace. > > I don't think you can put a 'use' inside a module, but you can use an > 'include'.  It may be a bug. > > e.g. Module fred(){ > > include<alibfile.scad>; > > } > > is ok, but > > module fred(){ > > use<alibfile.scad>; > > } > > is not > > Putting libraries of parts inside modules in the layout main file, > say, prevents anything in the part files polluting the layout file > space, or other part files,  but allows part values to be set, either > globally, or individually. > Let me see if I have the correct concept of the difference here. The first example above does not execute it until you include it in s statement such as "translate([,0,0,0]) "modulename in alibfile(args)" but if its a "use<alibfile.scad" you are telling it to execute it but there's no syntax to pass the "args" so it fails. right, wrong, or so far out its not even wrong as W. Pauli once wrote? Cheers, Gene Heskett. -- "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 Genes Web page <http://geneslinuxbox.net:6309/gene>
LM
Leonard Martin Struttmann
Sun, Oct 24, 2021 12:38 AM

Ray,  here's a simple working example:

File: stepper_motor_bracket.scad

height = 10;
width = 100;
length = 100;

constants =
[
["height",  height ],
["width",  width  ],
["length",  length ],
];

function stepper_motor_bracket( name ) =
let ( row = search( [name], constants )[0] )
row!=[]? constants[row][1] : 0;

module stepper_motor_bracket()
{
cube( [ length, width, height ] );
}

File: Assembly.scad

use <stepper_motor_bracket.scad>;

stepper_height = stepper_motor_bracket( "height" );
echo( "stepper_height", stepper_height );

stepper_motor_bracket();

On Sat, Oct 23, 2021 at 7:19 PM Gene Heskett gheskett@shentel.net wrote:

On Saturday 23 October 2021 19:59:43 Ray West wrote:

On 23/10/2021 22:45, Leonard Martin Struttmann wrote:

  1. Part files are never accessed with include<>.  They are accessed
    with use<>.  This avoids polluting my namespace.

I don't think you can put a 'use' inside a module, but you can use an
'include'.  It may be a bug.

e.g. Module fred(){

include<alibfile.scad>;

}

is ok, but

module fred(){

use<alibfile.scad>;

}

is not

Putting libraries of parts inside modules in the layout main file,
say, prevents anything in the part files polluting the layout file
space, or other part files,  but allows part values to be set, either
globally, or individually.

Let me see if I have the correct concept of the difference here.

The first example above does not execute it until you include it in s
statement such as
"translate([,0,0,0]) "modulename in alibfile(args)"

but if its a "use<alibfile.scad" you are telling it to execute it but
there's no syntax to pass the "args" so it fails. right, wrong, or so
far out its not even wrong as W. Pauli once wrote?

Cheers, Gene Heskett.

"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

Ray, here's a simple working example: File: stepper_motor_bracket.scad ------------------------------------------------- height = 10; width = 100; length = 100; constants = [ ["height", height ], ["width", width ], ["length", length ], ]; function stepper_motor_bracket( name ) = let ( row = search( [name], constants )[0] ) row!=[]? constants[row][1] : 0; module stepper_motor_bracket() { cube( [ length, width, height ] ); } ------------------------------------------------- File: Assembly.scad ------------------------------------------------- use <stepper_motor_bracket.scad>; stepper_height = stepper_motor_bracket( "height" ); echo( "stepper_height", stepper_height ); stepper_motor_bracket(); ------------------------------------------------- On Sat, Oct 23, 2021 at 7:19 PM Gene Heskett <gheskett@shentel.net> wrote: > On Saturday 23 October 2021 19:59:43 Ray West wrote: > > > On 23/10/2021 22:45, Leonard Martin Struttmann wrote: > > > 2. Part files are never accessed with include<>. They are accessed > > > with use<>. This avoids polluting my namespace. > > > > I don't think you can put a 'use' inside a module, but you can use an > > 'include'. It may be a bug. > > > > e.g. Module fred(){ > > > > include<alibfile.scad>; > > > > } > > > > is ok, but > > > > module fred(){ > > > > use<alibfile.scad>; > > > > } > > > > is not > > > > Putting libraries of parts inside modules in the layout main file, > > say, prevents anything in the part files polluting the layout file > > space, or other part files, but allows part values to be set, either > > globally, or individually. > > > Let me see if I have the correct concept of the difference here. > > The first example above does not execute it until you include it in s > statement such as > "translate([,0,0,0]) "modulename in alibfile(args)" > > but if its a "use<alibfile.scad" you are telling it to execute it but > there's no syntax to pass the "args" so it fails. right, wrong, or so > far out its not even wrong as W. Pauli once wrote? > > Cheers, Gene Heskett. > -- > "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 > Genes Web page <http://geneslinuxbox.net:6309/gene> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Sun, Oct 24, 2021 2:15 PM

On 10/23/2021 5:18 PM, Gene Heskett wrote:

On Saturday 23 October 2021 19:59:43 Ray West wrote:

I don't think you can put a 'use' inside a module, but you can use an
'include'.  It may be a bug.

e.g. Module fred(){

include<alibfile.scad>;

}

is ok, but

module fred(){

use<alibfile.scad>;

}

is not

Let me see if I have the correct concept of the difference here.

The first example above does not execute it until you include it in s
statement such as
"translate([,0,0,0]) "modulename in alibfile(args)"

but if its a "use<alibfile.scad" you are telling it to execute it but
there's no syntax to pass the "args" so it fails. right, wrong, or so
far out its not even wrong as W. Pauli once wrote?

An "include" is straight textual inclusion.  When it encounters the
"include" line, it reads in the file as if the two files were merged
together, without regard to the structure of the program.  Not that it
would be useful, but it appears that you can put the include at any
point, even (say) in the middle of an expression.

That is, you could have

// foo.scad
x = 2 +
include <bar.scad>

and

// bar.scad
2;

echo(x);

and it would work and print 4.

"use", on the other hand, is part of the structure of the program.  It
loads module and function definitions from the file, but does not
execute any module invocations.  Top-level assignments are executed at
the time of each call into the file.  (It is controversial whether this
is a bug or a feature and I don't want to get into that discussion here,
but it means that if the "used" file has many assignments or they do
complex work it can be a serious performance drag.)  Module and function
definitions are visible to the calling file, but top-level variable
assignments are not; this can help with namespace management.

A "use" in the middle of a module might in theory be meaningful, but is
not allowed.

On 10/23/2021 5:18 PM, Gene Heskett wrote: > On Saturday 23 October 2021 19:59:43 Ray West wrote: >> I don't think you can put a 'use' inside a module, but you can use an >> 'include'.  It may be a bug. >> >> e.g. Module fred(){ >> >> include<alibfile.scad>; >> >> } >> >> is ok, but >> >> module fred(){ >> >> use<alibfile.scad>; >> >> } >> >> is not > Let me see if I have the correct concept of the difference here. > > The first example above does not execute it until you include it in s > statement such as > "translate([,0,0,0]) "modulename in alibfile(args)" > > but if its a "use<alibfile.scad" you are telling it to execute it but > there's no syntax to pass the "args" so it fails. right, wrong, or so > far out its not even wrong as W. Pauli once wrote? > An "include" is straight textual inclusion.  When it encounters the "include" line, it reads in the file as if the two files were merged together, without regard to the structure of the program.  Not that it would be useful, but it appears that you can put the include at any point, even (say) in the middle of an expression. That is, you could have // foo.scad x = 2 + include <bar.scad> and // bar.scad 2; echo(x); and it would work and print 4. "use", on the other hand, is part of the structure of the program.  It loads module and function definitions from the file, but does not execute any module invocations.  Top-level assignments are executed at the time of each call into the file.  (It is controversial whether this is a bug or a feature and I don't want to get into that discussion here, but it means that if the "used" file has many assignments or they do complex work it can be a serious performance drag.)  Module and function definitions are visible to the calling file, but top-level variable assignments are not; this can help with namespace management. A "use" in the middle of a module might in theory be meaningful, but is not allowed.
GH
Gene Heskett
Sun, Oct 24, 2021 2:28 PM

On Sunday 24 October 2021 10:15:47 Jordan Brown wrote:

On 10/23/2021 5:18 PM, Gene Heskett wrote:

On Saturday 23 October 2021 19:59:43 Ray West wrote:

I don't think you can put a 'use' inside a module, but you can use
an 'include'.  It may be a bug.

e.g. Module fred(){

include<alibfile.scad>;

}

is ok, but

module fred(){

use<alibfile.scad>;

}

is not

Let me see if I have the correct concept of the difference here.

The first example above does not execute it until you include it in
s statement such as
"translate([,0,0,0]) "modulename in alibfile(args)"

but if its a "use<alibfile.scad" you are telling it to execute it
but there's no syntax to pass the "args" so it fails. right, wrong,
or so far out its not even wrong as W. Pauli once wrote?

An "include" is straight textual inclusion.  When it encounters the
"include" line, it reads in the file as if the two files were merged
together, without regard to the structure of the program.  Not that it
would be useful, but it appears that you can put the include at any
point, even (say) in the middle of an expression.

That is, you could have

 // foo.scad
 x = 2 +
 include <bar.scad>

and

 // bar.scad
 2;

 echo(x);

and it would work and print 4.

"use", on the other hand, is part of the structure of the program.  It
loads module and function definitions from the file, but does not
execute any module invocations.  Top-level assignments are executed at
the time of each call into the file.  (It is controversial whether
this is a bug or a feature and I don't want to get into that
discussion here, but it means that if the "used" file has many
assignments or they do complex work it can be a serious performance
drag.)  Module and function definitions are visible to the calling
file, but top-level variable assignments are not; this can help with
namespace management.

A "use" in the middle of a module might in theory be meaningful, but
is not allowed.

No need to Cc: me, I am subscribed, and many thanks for the
clarification,  Jordan.

Take care and stay well.

Cheers, Gene Heskett.

"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 Sunday 24 October 2021 10:15:47 Jordan Brown wrote: > On 10/23/2021 5:18 PM, Gene Heskett wrote: > > On Saturday 23 October 2021 19:59:43 Ray West wrote: > >> I don't think you can put a 'use' inside a module, but you can use > >> an 'include'.  It may be a bug. > >> > >> e.g. Module fred(){ > >> > >> include<alibfile.scad>; > >> > >> } > >> > >> is ok, but > >> > >> module fred(){ > >> > >> use<alibfile.scad>; > >> > >> } > >> > >> is not > > > > Let me see if I have the correct concept of the difference here. > > > > The first example above does not execute it until you include it in > > s statement such as > > "translate([,0,0,0]) "modulename in alibfile(args)" > > > > but if its a "use<alibfile.scad" you are telling it to execute it > > but there's no syntax to pass the "args" so it fails. right, wrong, > > or so far out its not even wrong as W. Pauli once wrote? > > An "include" is straight textual inclusion.  When it encounters the > "include" line, it reads in the file as if the two files were merged > together, without regard to the structure of the program.  Not that it > would be useful, but it appears that you can put the include at any > point, even (say) in the middle of an expression. > > That is, you could have > > // foo.scad > x = 2 + > include <bar.scad> > > and > > // bar.scad > 2; > > echo(x); > > and it would work and print 4. > > > "use", on the other hand, is part of the structure of the program.  It > loads module and function definitions from the file, but does not > execute any module invocations.  Top-level assignments are executed at > the time of each call into the file.  (It is controversial whether > this is a bug or a feature and I don't want to get into that > discussion here, but it means that if the "used" file has many > assignments or they do complex work it can be a serious performance > drag.)  Module and function definitions are visible to the calling > file, but top-level variable assignments are not; this can help with > namespace management. > > A "use" in the middle of a module might in theory be meaningful, but > is not allowed. No need to Cc: me, I am subscribed, and many thanks for the clarification, Jordan. Take care and stay well. Cheers, Gene Heskett. -- "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 Genes Web page <http://geneslinuxbox.net:6309/gene>
PC
Patrick Callahan
Sun, Oct 24, 2021 3:34 PM

Leonard,

That's an excellent way to encapsulate basic measures, and I think a
library of different-sized parts could work the same way with two
parameters.

My beginner work just had a module with all the parts' data as scalar
variables in one file called "measurements.scad."  It was fast becoming
less comfortable as the project grew.

I am a long-time procedural programmer, so using functions as a data store
is not second nature.

-Pat

On Sat, Oct 23, 2021 at 8:38 PM Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:

Ray,  here's a simple working example:

File: stepper_motor_bracket.scad

height = 10;
width = 100;
length = 100;

constants =
[
["height",  height ],
["width",  width  ],
["length",  length ],
];

function stepper_motor_bracket( name ) =
let ( row = search( [name], constants )[0] )
row!=[]? constants[row][1] : 0;

module stepper_motor_bracket()
{
cube( [ length, width, height ] );
}

File: Assembly.scad

use <stepper_motor_bracket.scad>;

stepper_height = stepper_motor_bracket( "height" );
echo( "stepper_height", stepper_height );

stepper_motor_bracket();

On Sat, Oct 23, 2021 at 7:19 PM Gene Heskett gheskett@shentel.net wrote:

On Saturday 23 October 2021 19:59:43 Ray West wrote:

On 23/10/2021 22:45, Leonard Martin Struttmann wrote:

  1. Part files are never accessed with include<>.  They are accessed
    with use<>.  This avoids polluting my namespace.

I don't think you can put a 'use' inside a module, but you can use an
'include'.  It may be a bug.

e.g. Module fred(){

include<alibfile.scad>;

}

is ok, but

module fred(){

use<alibfile.scad>;

}

is not

Putting libraries of parts inside modules in the layout main file,
say, prevents anything in the part files polluting the layout file
space, or other part files,  but allows part values to be set, either
globally, or individually.

Let me see if I have the correct concept of the difference here.

The first example above does not execute it until you include it in s
statement such as
"translate([,0,0,0]) "modulename in alibfile(args)"

but if its a "use<alibfile.scad" you are telling it to execute it but
there's no syntax to pass the "args" so it fails. right, wrong, or so
far out its not even wrong as W. Pauli once wrote?

Cheers, Gene Heskett.

"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


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Leonard, That's an excellent way to encapsulate basic measures, and I think a library of different-sized parts could work the same way with two parameters. My beginner work just had a module with all the parts' data as scalar variables in one file called "measurements.scad." It was fast becoming less comfortable as the project grew. I am a long-time procedural programmer, so using functions as a data store is not second nature. -Pat On Sat, Oct 23, 2021 at 8:38 PM Leonard Martin Struttmann < lenstruttmann@gmail.com> wrote: > Ray, here's a simple working example: > > File: stepper_motor_bracket.scad > ------------------------------------------------- > height = 10; > width = 100; > length = 100; > > constants = > [ > ["height", height ], > ["width", width ], > ["length", length ], > ]; > > function stepper_motor_bracket( name ) = > let ( row = search( [name], constants )[0] ) > row!=[]? constants[row][1] : 0; > > module stepper_motor_bracket() > { > cube( [ length, width, height ] ); > } > ------------------------------------------------- > > > > > File: Assembly.scad > ------------------------------------------------- > use <stepper_motor_bracket.scad>; > > stepper_height = stepper_motor_bracket( "height" ); > echo( "stepper_height", stepper_height ); > > stepper_motor_bracket(); > ------------------------------------------------- > > > On Sat, Oct 23, 2021 at 7:19 PM Gene Heskett <gheskett@shentel.net> wrote: > >> On Saturday 23 October 2021 19:59:43 Ray West wrote: >> >> > On 23/10/2021 22:45, Leonard Martin Struttmann wrote: >> > > 2. Part files are never accessed with include<>. They are accessed >> > > with use<>. This avoids polluting my namespace. >> > >> > I don't think you can put a 'use' inside a module, but you can use an >> > 'include'. It may be a bug. >> > >> > e.g. Module fred(){ >> > >> > include<alibfile.scad>; >> > >> > } >> > >> > is ok, but >> > >> > module fred(){ >> > >> > use<alibfile.scad>; >> > >> > } >> > >> > is not >> > >> > Putting libraries of parts inside modules in the layout main file, >> > say, prevents anything in the part files polluting the layout file >> > space, or other part files, but allows part values to be set, either >> > globally, or individually. >> > >> Let me see if I have the correct concept of the difference here. >> >> The first example above does not execute it until you include it in s >> statement such as >> "translate([,0,0,0]) "modulename in alibfile(args)" >> >> but if its a "use<alibfile.scad" you are telling it to execute it but >> there's no syntax to pass the "args" so it fails. right, wrong, or so >> far out its not even wrong as W. Pauli once wrote? >> >> Cheers, Gene Heskett. >> -- >> "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 >> Genes Web page <http://geneslinuxbox.net:6309/gene> >> _______________________________________________ >> 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 >
RW
Ray West
Sun, Oct 24, 2021 8:47 PM

On 24/10/2021 15:15, Jordan Brown wrote:

On 10/23/2021 5:18 PM, Gene Heskett wrote:

On Saturday 23 October 2021 19:59:43 Ray West wrote:

I don't think you can put a 'use' inside a module, but you can use an
'include'.  It may be a bug.

e.g. Module fred(){

include<alibfile.scad>;

}

is ok, but

module fred(){

use<alibfile.scad>;

}

is not

Let me see if I have the correct concept of the difference here.

The first example above does not execute it until you include it in s
statement such as
"translate([,0,0,0]) "modulename in alibfile(args)"

but if its a "use<alibfile.scad" you are telling it to execute it but
there's no syntax to pass the "args" so it fails. right, wrong, or so
far out its not even wrong as W. Pauli once wrote?

An "include" is straight textual inclusion.  When it encounters the
"include" line, it reads in the file as if the two files were merged
together, without regard to the structure of the program. Not that it
would be useful, but it appears that you can put the include at any
point, even (say) in the middle of an expression.

That is, you could have

 // foo.scad
 x = 2 +
 include <bar.scad>

and

 // bar.scad
 2;

 echo(x);

and it would work and print 4.

"use", on the other hand, is part of the structure of the program.  It
loads module and function definitions from the file, but does not
execute any module invocations.  Top-level assignments are executed at
the time of each call into the file. (It is controversial whether this
is a bug or a feature and I don't want to get into that discussion
here, but it means that if the "used" file has many assignments or
they do complex work it can be a serious performance drag.)  Module
and function definitions are visible to the calling file, but
top-level variable assignments are not; this can help with namespace
management.

A "use" in the middle of a module might in theory be meaningful, but
is not allowed.

Hi Jordan, thanks for the explanation, it is a bug then 😉  . For me,
tthe differance between use and include, its that if using an include
I have to comment out 'test code' in the file that I am including.  No
big deal.

Best wishes,

Ray

On 24/10/2021 15:15, Jordan Brown wrote: > On 10/23/2021 5:18 PM, Gene Heskett wrote: >> On Saturday 23 October 2021 19:59:43 Ray West wrote: >>> I don't think you can put a 'use' inside a module, but you can use an >>> 'include'.  It may be a bug. >>> >>> e.g. Module fred(){ >>> >>> include<alibfile.scad>; >>> >>> } >>> >>> is ok, but >>> >>> module fred(){ >>> >>> use<alibfile.scad>; >>> >>> } >>> >>> is not >> Let me see if I have the correct concept of the difference here. >> >> The first example above does not execute it until you include it in s >> statement such as >> "translate([,0,0,0]) "modulename in alibfile(args)" >> >> but if its a "use<alibfile.scad" you are telling it to execute it but >> there's no syntax to pass the "args" so it fails. right, wrong, or so >> far out its not even wrong as W. Pauli once wrote? >> > > An "include" is straight textual inclusion.  When it encounters the > "include" line, it reads in the file as if the two files were merged > together, without regard to the structure of the program. Not that it > would be useful, but it appears that you can put the include at any > point, even (say) in the middle of an expression. > > That is, you could have > > // foo.scad > x = 2 + > include <bar.scad> > > and > > // bar.scad > 2; > > echo(x); > > and it would work and print 4. > > > "use", on the other hand, is part of the structure of the program.  It > loads module and function definitions from the file, but does not > execute any module invocations.  Top-level assignments are executed at > the time of each call into the file. (It is controversial whether this > is a bug or a feature and I don't want to get into that discussion > here, but it means that if the "used" file has many assignments or > they do complex work it can be a serious performance drag.)  Module > and function definitions are visible to the calling file, but > top-level variable assignments are not; this can help with namespace > management. > > A "use" in the middle of a module might in theory be meaningful, but > is not allowed. > > > Hi Jordan, thanks for the explanation, it is a bug then 😉  . For me, > tthe differance between use and include, its that if using an include > I have to comment out 'test code' in the file that I am including.  No > big deal. Best wishes, Ray