discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: Dynamic Include

AM
Adrian Mariano
Fri, Nov 25, 2022 8:48 PM

So nophead has suggested that it doesn't really work, and it seems like
he's probably right.  The problem is you have no way to know whether the
code loads unless loading the code is slow enough that you can tell it
happened.  My approach definitely works programmatically, but I suspect it
still loads all of the included files.  So it doesn't present any advantage
from just loading them at the beginning---unless you want to load
conflicting files, I suppose.

Note that nophead also said you can't include inside modules.  That is
incorrect.  I tried this:

module aa(){
include<a.scad>
echo(a=a);
}

aa();

where a.scad simply contains "a=3;" and it runs and produces the expected
output.  To test things a little farther, I changed the definition in the
file to "a=3" with no semicolon and in my module I did "include<a.scad> +
4;" and then it prints a=7.  So it looks to me like include simply inserts
the file contents into the stream of your program.  Presumably it gets
parsed as usual.  And it doesn't seem to matter how it crosses boundaries
of programming structures.  To check this further I put a.scad to

module aa(){
a=3;

and then I set b.scad to

echo(a=a);
}

and finally my top level program was:

include<a.scad>
include<b.scad>

aa();

And even this worked.  This builds a pretty compelling case that every
include is loaded, because otherwise it can't parse your code.  So this
idea will not prevent your 1 MB of data from being loaded.

On Fri, Nov 25, 2022 at 3:39 PM Trevor Orr via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: Trevor Orr fractorr@yahoo.com
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc:
Bcc:
Date: Fri, 25 Nov 2022 20:38:14 +0000 (UTC)
Subject: [OpenSCAD] Re: Dynamic Include
Cool, the if include statement does seem to work.

On Friday, November 25, 2022 at 12:09:01 PM PST, Adrian Mariano <
avm4@cornell.edu> wrote:

Presumably larger files take longer to be parsed...but you can run your
program and see how long it takes.  Does including the file give a
significant performance hit?  I'd guess not, since reading a MB doesn't
take very long compared to OpenSCAD render, say.  Including BOSL2/std.scad
appears to take negligible time and it's 1.5 MB in 28 files.

i think you can do a dynamic include only in the context of an "if" block,
which means the included content will be scoped to the conditional block.
So you could do something like

if (part1) {
include<part1.scad>

 code here to make part 1

}

But the stuff included would not be available at the top level.  Note, I
haven't tested this.

On Fri, Nov 25, 2022 at 2:59 PM Trevor Orr via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: Trevor Orr fractorr@yahoo.com
To: OpenSCAD General Discussion Mailing-list discuss@lists.openscad.org
Cc:
Bcc:
Date: Fri, 25 Nov 2022 19:57:55 +0000 (UTC)
Subject: [OpenSCAD] Dynamic Include
I am pretty sure this is not possible from my attempts to do this but
thought I would ask anyways.

Is there a way to do a dynamic include base on the value of variable ?
The reason is that I have a file that contains data to build parts and the
data file is getting rather large (almost 1 MB) and it would be nice to be
able to split it up into a separate file for each part.

So say the variable design equals "test" then I want to include the file
"test.scad"

Also does a large data file like this decrease performance?  I would
assume the larger the data file is the longer it takes for it to be parsed?

---------- Forwarded message ----------
From: Trevor Orr via Discuss discuss@lists.openscad.org
To: OpenSCAD General Discussion Mailing-list discuss@lists.openscad.org
Cc: Trevor Orr fractorr@yahoo.com
Bcc:
Date: Fri, 25 Nov 2022 19:57:55 +0000 (UTC)
Subject: [OpenSCAD] Dynamic 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

---------- Forwarded message ----------
From: Trevor Orr via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: Trevor Orr fractorr@yahoo.com
Bcc:
Date: Fri, 25 Nov 2022 20:38:14 +0000 (UTC)
Subject: [OpenSCAD] Re: Dynamic Include


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

So nophead has suggested that it doesn't really work, and it seems like he's probably right. The problem is you have no way to know whether the code loads unless loading the code is slow enough that you can tell it happened. My approach definitely works programmatically, but I suspect it still loads all of the included files. So it doesn't present any advantage from just loading them at the beginning---unless you want to load conflicting files, I suppose. Note that nophead also said you can't include inside modules. That is incorrect. I tried this: module aa(){ include<a.scad> echo(a=a); } aa(); where a.scad simply contains "a=3;" and it runs and produces the expected output. To test things a little farther, I changed the definition in the file to "a=3" with no semicolon and in my module I did "include<a.scad> + 4;" and then it prints a=7. So it looks to me like include simply inserts the file contents into the stream of your program. Presumably it gets parsed as usual. And it doesn't seem to matter how it crosses boundaries of programming structures. To check this further I put a.scad to module aa(){ a=3; and then I set b.scad to echo(a=a); } and finally my top level program was: include<a.scad> include<b.scad> aa(); And even this worked. This builds a pretty compelling case that every include is loaded, because otherwise it can't parse your code. So this idea will not prevent your 1 MB of data from being loaded. On Fri, Nov 25, 2022 at 3:39 PM Trevor Orr via Discuss < discuss@lists.openscad.org> wrote: > > > > ---------- Forwarded message ---------- > From: Trevor Orr <fractorr@yahoo.com> > To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Fri, 25 Nov 2022 20:38:14 +0000 (UTC) > Subject: [OpenSCAD] Re: Dynamic Include > Cool, the if include statement does seem to work. > > On Friday, November 25, 2022 at 12:09:01 PM PST, Adrian Mariano < > avm4@cornell.edu> wrote: > > > Presumably larger files take longer to be parsed...but you can run your > program and see how long it takes. Does including the file give a > significant performance hit? I'd guess not, since reading a MB doesn't > take very long compared to OpenSCAD render, say. Including BOSL2/std.scad > appears to take negligible time and it's 1.5 MB in 28 files. > > i think you can do a dynamic include only in the context of an "if" block, > which means the included content will be scoped to the conditional block. > So you could do something like > > if (part1) { > include<part1.scad> > > code here to make part 1 > } > > But the stuff included would not be available at the top level. Note, I > haven't tested this. > > > On Fri, Nov 25, 2022 at 2:59 PM Trevor Orr via Discuss < > discuss@lists.openscad.org> wrote: > > > > > ---------- Forwarded message ---------- > From: Trevor Orr <fractorr@yahoo.com> > To: OpenSCAD General Discussion Mailing-list <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Fri, 25 Nov 2022 19:57:55 +0000 (UTC) > Subject: [OpenSCAD] Dynamic Include > I am pretty sure this is not possible from my attempts to do this but > thought I would ask anyways. > > Is there a way to do a dynamic include base on the value of variable ? > The reason is that I have a file that contains data to build parts and the > data file is getting rather large (almost 1 MB) and it would be nice to be > able to split it up into a separate file for each part. > > So say the variable design equals "test" then I want to include the file > "test.scad" > > Also does a large data file like this decrease performance? I would > assume the larger the data file is the longer it takes for it to be parsed? > > > > > ---------- Forwarded message ---------- > From: Trevor Orr via Discuss <discuss@lists.openscad.org> > To: OpenSCAD General Discussion Mailing-list <discuss@lists.openscad.org> > Cc: Trevor Orr <fractorr@yahoo.com> > Bcc: > Date: Fri, 25 Nov 2022 19:57:55 +0000 (UTC) > Subject: [OpenSCAD] Dynamic 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 > > > > ---------- Forwarded message ---------- > From: Trevor Orr via Discuss <discuss@lists.openscad.org> > To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> > Cc: Trevor Orr <fractorr@yahoo.com> > Bcc: > Date: Fri, 25 Nov 2022 20:38:14 +0000 (UTC) > Subject: [OpenSCAD] Re: Dynamic Include > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
NH
nop head
Fri, Nov 25, 2022 8:53 PM

I didn't say you can't put includes in modules. What I said was you can't
define modules inside an if block. So if your include is inside an if block
it can't define modules in the included file.

On Fri, 25 Nov 2022 at 20:49, Adrian Mariano avm4@cornell.edu wrote:

So nophead has suggested that it doesn't really work, and it seems like
he's probably right.  The problem is you have no way to know whether the
code loads unless loading the code is slow enough that you can tell it
happened.  My approach definitely works programmatically, but I suspect it
still loads all of the included files.  So it doesn't present any advantage
from just loading them at the beginning---unless you want to load
conflicting files, I suppose.

Note that nophead also said you can't include inside modules.  That is
incorrect.  I tried this:

module aa(){
include<a.scad>
echo(a=a);
}

aa();

where a.scad simply contains "a=3;" and it runs and produces the expected
output.  To test things a little farther, I changed the definition in the
file to "a=3" with no semicolon and in my module I did "include<a.scad> +
4;" and then it prints a=7.  So it looks to me like include simply inserts
the file contents into the stream of your program.  Presumably it gets
parsed as usual.  And it doesn't seem to matter how it crosses boundaries
of programming structures.  To check this further I put a.scad to

module aa(){
a=3;

and then I set b.scad to

echo(a=a);
}

and finally my top level program was:

include<a.scad>
include<b.scad>

aa();

And even this worked.  This builds a pretty compelling case that every
include is loaded, because otherwise it can't parse your code.  So this
idea will not prevent your 1 MB of data from being loaded.

On Fri, Nov 25, 2022 at 3:39 PM Trevor Orr via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: Trevor Orr fractorr@yahoo.com
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc:
Bcc:
Date: Fri, 25 Nov 2022 20:38:14 +0000 (UTC)
Subject: [OpenSCAD] Re: Dynamic Include
Cool, the if include statement does seem to work.

On Friday, November 25, 2022 at 12:09:01 PM PST, Adrian Mariano <
avm4@cornell.edu> wrote:

Presumably larger files take longer to be parsed...but you can run your
program and see how long it takes.  Does including the file give a
significant performance hit?  I'd guess not, since reading a MB doesn't
take very long compared to OpenSCAD render, say.  Including BOSL2/std.scad
appears to take negligible time and it's 1.5 MB in 28 files.

i think you can do a dynamic include only in the context of an "if"
block, which means the included content will be scoped to the conditional
block.  So you could do something like

if (part1) {
include<part1.scad>

 code here to make part 1

}

But the stuff included would not be available at the top level.  Note, I
haven't tested this.

On Fri, Nov 25, 2022 at 2:59 PM Trevor Orr via Discuss <
discuss@lists.openscad.org> wrote:

---------- Forwarded message ----------
From: Trevor Orr fractorr@yahoo.com
To: OpenSCAD General Discussion Mailing-list discuss@lists.openscad.org
Cc:
Bcc:
Date: Fri, 25 Nov 2022 19:57:55 +0000 (UTC)
Subject: [OpenSCAD] Dynamic Include
I am pretty sure this is not possible from my attempts to do this but
thought I would ask anyways.

Is there a way to do a dynamic include base on the value of variable ?
The reason is that I have a file that contains data to build parts and the
data file is getting rather large (almost 1 MB) and it would be nice to be
able to split it up into a separate file for each part.

So say the variable design equals "test" then I want to include the file
"test.scad"

Also does a large data file like this decrease performance?  I would
assume the larger the data file is the longer it takes for it to be parsed?

---------- Forwarded message ----------
From: Trevor Orr via Discuss discuss@lists.openscad.org
To: OpenSCAD General Discussion Mailing-list discuss@lists.openscad.org
Cc: Trevor Orr fractorr@yahoo.com
Bcc:
Date: Fri, 25 Nov 2022 19:57:55 +0000 (UTC)
Subject: [OpenSCAD] Dynamic 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

---------- Forwarded message ----------
From: Trevor Orr via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion Mailing-list discuss@lists.openscad.org
Cc: Trevor Orr fractorr@yahoo.com
Bcc:
Date: Fri, 25 Nov 2022 20:38:14 +0000 (UTC)
Subject: [OpenSCAD] Re: Dynamic 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

I didn't say you can't put includes in modules. What I said was you can't define modules inside an if block. So if your include is inside an if block it can't define modules in the included file. On Fri, 25 Nov 2022 at 20:49, Adrian Mariano <avm4@cornell.edu> wrote: > So nophead has suggested that it doesn't really work, and it seems like > he's probably right. The problem is you have no way to know whether the > code loads unless loading the code is slow enough that you can tell it > happened. My approach definitely works programmatically, but I suspect it > still loads all of the included files. So it doesn't present any advantage > from just loading them at the beginning---unless you want to load > conflicting files, I suppose. > > Note that nophead also said you can't include inside modules. That is > incorrect. I tried this: > > module aa(){ > include<a.scad> > echo(a=a); > } > > > aa(); > > where a.scad simply contains "a=3;" and it runs and produces the expected > output. To test things a little farther, I changed the definition in the > file to "a=3" with no semicolon and in my module I did "include<a.scad> + > 4;" and then it prints a=7. So it looks to me like include simply inserts > the file contents into the stream of your program. Presumably it gets > parsed as usual. And it doesn't seem to matter how it crosses boundaries > of programming structures. To check this further I put a.scad to > > module aa(){ > a=3; > > and then I set b.scad to > > echo(a=a); > } > > and finally my top level program was: > > include<a.scad> > include<b.scad> > > aa(); > > > And even this worked. This builds a pretty compelling case that every > include is loaded, because otherwise it can't parse your code. So this > idea will not prevent your 1 MB of data from being loaded. > > On Fri, Nov 25, 2022 at 3:39 PM Trevor Orr via Discuss < > discuss@lists.openscad.org> wrote: > >> >> >> >> ---------- Forwarded message ---------- >> From: Trevor Orr <fractorr@yahoo.com> >> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> >> Cc: >> Bcc: >> Date: Fri, 25 Nov 2022 20:38:14 +0000 (UTC) >> Subject: [OpenSCAD] Re: Dynamic Include >> Cool, the if include statement does seem to work. >> >> On Friday, November 25, 2022 at 12:09:01 PM PST, Adrian Mariano < >> avm4@cornell.edu> wrote: >> >> >> Presumably larger files take longer to be parsed...but you can run your >> program and see how long it takes. Does including the file give a >> significant performance hit? I'd guess not, since reading a MB doesn't >> take very long compared to OpenSCAD render, say. Including BOSL2/std.scad >> appears to take negligible time and it's 1.5 MB in 28 files. >> >> i think you can do a dynamic include only in the context of an "if" >> block, which means the included content will be scoped to the conditional >> block. So you could do something like >> >> if (part1) { >> include<part1.scad> >> >> code here to make part 1 >> } >> >> But the stuff included would not be available at the top level. Note, I >> haven't tested this. >> >> >> On Fri, Nov 25, 2022 at 2:59 PM Trevor Orr via Discuss < >> discuss@lists.openscad.org> wrote: >> >> >> >> >> ---------- Forwarded message ---------- >> From: Trevor Orr <fractorr@yahoo.com> >> To: OpenSCAD General Discussion Mailing-list <discuss@lists.openscad.org> >> Cc: >> Bcc: >> Date: Fri, 25 Nov 2022 19:57:55 +0000 (UTC) >> Subject: [OpenSCAD] Dynamic Include >> I am pretty sure this is not possible from my attempts to do this but >> thought I would ask anyways. >> >> Is there a way to do a dynamic include base on the value of variable ? >> The reason is that I have a file that contains data to build parts and the >> data file is getting rather large (almost 1 MB) and it would be nice to be >> able to split it up into a separate file for each part. >> >> So say the variable design equals "test" then I want to include the file >> "test.scad" >> >> Also does a large data file like this decrease performance? I would >> assume the larger the data file is the longer it takes for it to be parsed? >> >> >> >> >> ---------- Forwarded message ---------- >> From: Trevor Orr via Discuss <discuss@lists.openscad.org> >> To: OpenSCAD General Discussion Mailing-list <discuss@lists.openscad.org> >> Cc: Trevor Orr <fractorr@yahoo.com> >> Bcc: >> Date: Fri, 25 Nov 2022 19:57:55 +0000 (UTC) >> Subject: [OpenSCAD] Dynamic 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 >> >> >> >> ---------- Forwarded message ---------- >> From: Trevor Orr via Discuss <discuss@lists.openscad.org> >> To: OpenSCAD general discussion Mailing-list <discuss@lists.openscad.org> >> Cc: Trevor Orr <fractorr@yahoo.com> >> Bcc: >> Date: Fri, 25 Nov 2022 20:38:14 +0000 (UTC) >> Subject: [OpenSCAD] Re: Dynamic 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 >