discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Possible to name a 'chunk' of code, then use its name?

MM
Michael Möller
Wed, Feb 9, 2022 5:59 PM

" any future use of the string ‘shaftxyz’ (apart from this specific
statement) would effectively replace that code."

That is called a text macro, i.e. it is something an editor does. You can
use ANY editor to create the OpenSCAD code, and then use OpenSCAD to
compile/visualise it.
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_an_external_Editor_with_OpenSCAD

Or you write your code using "shaftxyz", then use Ctrl-Shift-F and ask to
replace all "shaftxyz" occurrences with "cylinder( ..." in your code.

Either way - using a text editor/replace - from then onwards the "shaftxyz"
text is no longer there. There is the (possibly complicated) "cylinder(
..." code.

Which is why the modules is better. There will always be "shaftxyz()" in
your code. Yes, you need to type an extra "()" after it, but otherwise that
does what you want.

"Oh but I first have to write the module" - you say (perhaps. Well, you had
to write the text macro or the replacement string, too, so you are no worse
off, AND it is in the code, instead of hidden in an external text editor.
Also note you do not have to have parameters. Even if your module has
parameters, they can be made optional by giving them a default value so the
calling code can be "shaftxyz()" for the standard shaft, and
"shaftxyz(L=100)" for an exceptional long one.

I really have a hard time understanding a reason for NOT using modules. As
opposed to an executable program you can use modules as much as you like,
and it will have immeasurably little time effect on your compilation. It
probably even will speed your rendering, due to caching (Your Mileage May
Vary)

Msquare

NB: "Getting better at modules" you're only going to get better by actually
using them. Simplistic "text substitution" to start with, and then
gradually work your way up

On Wed, 9 Feb 2022 at 14:52, terrypingm@gmail.com terrypingm@gmail.com
wrote:

Thanks nop head. Although I understand the greater fexibility of modules,
I naively had in mind something much simpler. While still editing my code,
say that subtraction on my two cylinders is done. I’d like to bracket that
code, place my cursor at the start and type something like ‘Define
shaftxyz:’ So that any future use of the string ‘shaftxyz’ (apart from this
specific statement) would effectively replace that code. No decisions about
future use, no decision whether parameters needed and if so what to call
them. Just like my abbreviation ‘=tp’ to type my full name and address.

--
Terry

On 9 Feb 2022, at 12:53, nop head nop.head@gmail.com wrote:


Yes, make it a module called shaft and use shaft().

On Wed, 9 Feb 2022 at 12:50, Terry Pinnell terrypingm@gmail.com wrote:

Probably an embarrassingly obvious answer, but..

When building a model, say a shaft for a spindle, suppose I start with
subtracting a smaller cylinder from another. Developing that, the code can
soon get quite messy. Differences of differences and the like. Is there a
simple way to name my model, say 'Shaft', and then use that name in all
further editing?

--
Terry


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


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

" any future use of the string ‘shaftxyz’ (apart from this specific statement) would effectively replace that code." That is called a text macro, i.e. it is something an editor does. You can use ANY editor to create the OpenSCAD code, and then use OpenSCAD to compile/visualise it. https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_an_external_Editor_with_OpenSCAD Or you write your code using "shaftxyz", then use Ctrl-Shift-F and ask to replace all "shaftxyz" occurrences with "cylinder( ..." in your code. Either way - using a text editor/replace - from then onwards the "shaftxyz" text is no longer there. There is the (possibly complicated) "cylinder( ..." code. Which is why the modules is better. There will always be "shaftxyz()" in your code. Yes, you need to type an extra "()" after it, but otherwise that does what you want. "Oh but I first have to write the module" - you say (perhaps. Well, you had to write the text macro or the replacement string, too, so you are no worse off, AND it is in the code, instead of hidden in an external text editor. Also note you do not have to have parameters. Even if your module has parameters, they can be made optional by giving them a default value so the calling code can be "shaftxyz()" for the standard shaft, and "shaftxyz(L=100)" for an exceptional long one. I really have a hard time understanding a reason for NOT using modules. As opposed to an executable program you can use modules as much as you like, and it will have immeasurably little time effect on your compilation. It probably even will speed your rendering, due to caching (Your Mileage May Vary) Msquare NB: "Getting better at modules" you're only going to get better by actually using them. Simplistic "text substitution" to start with, and then gradually work your way up On Wed, 9 Feb 2022 at 14:52, terrypingm@gmail.com <terrypingm@gmail.com> wrote: > Thanks nop head. Although I understand the greater fexibility of modules, > I naively had in mind something much simpler. While still editing my code, > say that subtraction on my two cylinders is done. I’d like to bracket that > code, place my cursor at the start and type something like ‘Define > shaftxyz:’ So that any future use of the string ‘shaftxyz’ (apart from this > specific statement) would effectively replace that code. No decisions about > future use, no decision whether parameters needed and if so what to call > them. Just like my abbreviation ‘=tp’ to type my full name and address. > > -- > Terry > > On 9 Feb 2022, at 12:53, nop head <nop.head@gmail.com> wrote: > >  > Yes, make it a module called shaft and use shaft(). > > On Wed, 9 Feb 2022 at 12:50, Terry Pinnell <terrypingm@gmail.com> wrote: > >> Probably an embarrassingly obvious answer, but.. >> >> When building a model, say a shaft for a spindle, suppose I start with >> subtracting a smaller cylinder from another. Developing that, the code can >> soon get quite messy. Differences of differences and the like. Is there a >> simple way to name my model, say 'Shaft', and then use that name in all >> further editing? >> >> -- >> Terry >> _______________________________________________ >> 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 > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
FS
FF Systems
Wed, Feb 9, 2022 6:15 PM

I echo what M^2 says.  I was reluctant to use modules at first, but now I
use them freely.  It really is EXACTLY what you originally asked for.
PLUS, you can pass parameters when you get used to the syntax.  The modules
then start to become more generic and you can customize them based on how
you want to use a particular instance.  For example, I have a countersink
shape that I use to create countersinks in difference() stacks (BOSL2 and
other libraries likely have similar constructs, but I created my own).  I
can pass a parameter to set the screw size for the CS.  Once I had coded
the module to produce the right size based on the passed parameter (a "2"
or "4", etc...) I can now reuse the object and set it to the size I want on
the fly.

Coding in openSCAD is just like coding for computer programs, you can't
read your way to expertise, you have to CODE your way to it.

PS: Compiler MACROS are constructs like M^2 alluded towards... they are
text replacements made by the compiler/assembler for computer programs.
They can increase code speed because the overhead of calling the
function/subroutine is eliminated (useful for interrupts or looping
constructs).  In openSCAD, there is no such benefit to be reaped, so the
practice has no corollary.  Thus, modules() are what you have here.

On Wed, Feb 9, 2022 at 11:59 AM Michael Möller private2michael@gmail.com
wrote:

" any future use of the string ‘shaftxyz’ (apart from this specific
statement) would effectively replace that code."

That is called a text macro, i.e. it is something an editor does. You can
use ANY editor to create the OpenSCAD code, and then use OpenSCAD to
compile/visualise it.
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_an_external_Editor_with_OpenSCAD

Or you write your code using "shaftxyz", then use Ctrl-Shift-F and ask to
replace all "shaftxyz" occurrences with "cylinder( ..." in your code.

Either way - using a text editor/replace - from then onwards the
"shaftxyz" text is no longer there. There is the (possibly complicated)
"cylinder( ..." code.

Which is why the modules is better. There will always be "shaftxyz()" in
your code. Yes, you need to type an extra "()" after it, but otherwise that
does what you want.

"Oh but I first have to write the module" - you say (perhaps. Well, you
had to write the text macro or the replacement string, too, so you are no
worse off, AND it is in the code, instead of hidden in an external text
editor. Also note you do not have to have parameters. Even if your module
has parameters, they can be made optional by giving them a default value so
the calling code can be "shaftxyz()" for the standard shaft, and
"shaftxyz(L=100)" for an exceptional long one.

I really have a hard time understanding a reason for NOT using modules. As
opposed to an executable program you can use modules as much as you like,
and it will have immeasurably little time effect on your compilation. It
probably even will speed your rendering, due to caching (Your Mileage May
Vary)

Msquare

NB: "Getting better at modules" you're only going to get better by
actually using them. Simplistic "text substitution" to start with, and then
gradually work your way up

On Wed, 9 Feb 2022 at 14:52, terrypingm@gmail.com terrypingm@gmail.com
wrote:

Thanks nop head. Although I understand the greater fexibility of modules,
I naively had in mind something much simpler. While still editing my code,
say that subtraction on my two cylinders is done. I’d like to bracket that
code, place my cursor at the start and type something like ‘Define
shaftxyz:’ So that any future use of the string ‘shaftxyz’ (apart from this
specific statement) would effectively replace that code. No decisions about
future use, no decision whether parameters needed and if so what to call
them. Just like my abbreviation ‘=tp’ to type my full name and address.

--
Terry

On 9 Feb 2022, at 12:53, nop head nop.head@gmail.com wrote:


Yes, make it a module called shaft and use shaft().

On Wed, 9 Feb 2022 at 12:50, Terry Pinnell terrypingm@gmail.com wrote:

Probably an embarrassingly obvious answer, but..

When building a model, say a shaft for a spindle, suppose I start with
subtracting a smaller cylinder from another. Developing that, the code can
soon get quite messy. Differences of differences and the like. Is there a
simple way to name my model, say 'Shaft', and then use that name in all
further editing?

--
Terry


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


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 echo what M^2 says. I was reluctant to use modules at first, but now I use them freely. It really is EXACTLY what you originally asked for. PLUS, you can pass parameters when you get used to the syntax. The modules then start to become more generic and you can customize them based on how you want to use a particular instance. For example, I have a countersink shape that I use to create countersinks in difference() stacks (BOSL2 and other libraries likely have similar constructs, but I created my own). I can pass a parameter to set the screw size for the CS. Once I had coded the module to produce the right size based on the passed parameter (a "2" or "4", etc...) I can now reuse the object and set it to the size I want on the fly. Coding in openSCAD is just like coding for computer programs, you can't read your way to expertise, you have to CODE your way to it. PS: Compiler MACROS are constructs like M^2 alluded towards... they are text replacements made by the compiler/assembler for computer programs. They can increase code speed because the overhead of calling the function/subroutine is eliminated (useful for interrupts or looping constructs). In openSCAD, there is no such benefit to be reaped, so the practice has no corollary. Thus, modules() are what you have here. On Wed, Feb 9, 2022 at 11:59 AM Michael Möller <private2michael@gmail.com> wrote: > " any future use of the string ‘shaftxyz’ (apart from this specific > statement) would effectively replace that code." > > That is called a text macro, i.e. it is something an editor does. You can > use ANY editor to create the OpenSCAD code, and then use OpenSCAD to > compile/visualise it. > https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_an_external_Editor_with_OpenSCAD > > Or you write your code using "shaftxyz", then use Ctrl-Shift-F and ask to > replace all "shaftxyz" occurrences with "cylinder( ..." in your code. > > Either way - using a text editor/replace - from then onwards the > "shaftxyz" text is no longer there. There is the (possibly complicated) > "cylinder( ..." code. > > Which is why the modules is better. There will always be "shaftxyz()" in > your code. Yes, you need to type an extra "()" after it, but otherwise that > does what you want. > > "Oh but I first have to write the module" - you say (perhaps. Well, you > had to write the text macro or the replacement string, too, so you are no > worse off, AND it is in the code, instead of hidden in an external text > editor. Also note you do not have to have parameters. Even if your module > has parameters, they can be made optional by giving them a default value so > the calling code can be "shaftxyz()" for the standard shaft, and > "shaftxyz(L=100)" for an exceptional long one. > > I really have a hard time understanding a reason for NOT using modules. As > opposed to an executable program you can use modules as much as you like, > and it will have immeasurably little time effect on your compilation. It > probably even will speed your rendering, due to caching (Your Mileage May > Vary) > > Msquare > > NB: "Getting better at modules" you're only going to get better by > actually using them. Simplistic "text substitution" to start with, and then > gradually work your way up > > > On Wed, 9 Feb 2022 at 14:52, terrypingm@gmail.com <terrypingm@gmail.com> > wrote: > >> Thanks nop head. Although I understand the greater fexibility of modules, >> I naively had in mind something much simpler. While still editing my code, >> say that subtraction on my two cylinders is done. I’d like to bracket that >> code, place my cursor at the start and type something like ‘Define >> shaftxyz:’ So that any future use of the string ‘shaftxyz’ (apart from this >> specific statement) would effectively replace that code. No decisions about >> future use, no decision whether parameters needed and if so what to call >> them. Just like my abbreviation ‘=tp’ to type my full name and address. >> >> -- >> Terry >> >> On 9 Feb 2022, at 12:53, nop head <nop.head@gmail.com> wrote: >> >>  >> Yes, make it a module called shaft and use shaft(). >> >> On Wed, 9 Feb 2022 at 12:50, Terry Pinnell <terrypingm@gmail.com> wrote: >> >>> Probably an embarrassingly obvious answer, but.. >>> >>> When building a model, say a shaft for a spindle, suppose I start with >>> subtracting a smaller cylinder from another. Developing that, the code can >>> soon get quite messy. Differences of differences and the like. Is there a >>> simple way to name my model, say 'Shaft', and then use that name in all >>> further editing? >>> >>> -- >>> Terry >>> _______________________________________________ >>> 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 >> >> _______________________________________________ >> 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 >
TP
Torsten Paul
Wed, Feb 9, 2022 6:29 PM

I agree on what's said on using modules, but I'm not sure
that's what the original question is asking for.

It sounds to me the feature that's been asked for is actually
an editor-only feature to type shortcuts.

E.g. when writing Java code in Netbeans, I can type:

sout<TAB> and that will expand to System.out.println("");
with the cursor placed between the quotes.

OpenSCAD has something similar, more targeting bigger
snippets of code via <Right Mouse Click> -> Insert Template.

Having the shorter form that does that simpler text
replacement might still be useful in addition, e.g. with
the example given earlier it would:

=tp<TAB>

expand to the text

Terry ... <email-address>

replacing the =tp.

ciao,
Torsten.

I agree on what's said on using modules, but I'm not sure that's what the original question is asking for. It sounds to me the feature that's been asked for is actually an editor-only feature to type shortcuts. E.g. when writing Java code in Netbeans, I can type: sout<TAB> and that will expand to System.out.println(""); with the cursor placed between the quotes. OpenSCAD has something similar, more targeting bigger snippets of code via <Right Mouse Click> -> Insert Template. Having the shorter form that does that simpler text replacement might still be useful in addition, e.g. with the example given earlier it would: =tp<TAB> expand to the text Terry ... <email-address> replacing the =tp. ciao, Torsten.
TP
Terry Pinnell
Wed, Feb 9, 2022 7:30 PM

Thanks all. OK, I'll get stuck into using modules. I expect it will take a
while before I really feel comfortable. So I'll also try other shortcuts.

I also need to explore using an external editor, I've avoided it because
I'm hitting F5 after virtually every edit. Trial and error plays a big part
in my workflow. But I'd benefit from the superior features an external
editor can offer. For example, simply changing the text or background
colour would help keeping track of what code a difference(),union(),
rotate(), etc is about to be operated on.

Earlier today I did play with 'include <pipe.h>', but of course that merely
pastes the text into the code once.

I still think a simple feature of the sort I described could be helpful to
complement the other tools.

On Wed, 9 Feb 2022 at 18:29, Torsten Paul Torsten.Paul@gmx.de wrote:

I agree on what's said on using modules, but I'm not sure
that's what the original question is asking for.

It sounds to me the feature that's been asked for is actually
an editor-only feature to type shortcuts.

E.g. when writing Java code in Netbeans, I can type:

sout<TAB> and that will expand to System.out.println("");
with the cursor placed between the quotes.

OpenSCAD has something similar, more targeting bigger
snippets of code via <Right Mouse Click> -> Insert Template.

Having the shorter form that does that simpler text
replacement might still be useful in addition, e.g. with
the example given earlier it would:

=tp<TAB>

expand to the text

Terry ... <email-address>

replacing the =tp.

ciao,
Torsten.


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

Thanks all. OK, I'll get stuck into using modules. I expect it will take a while before I really feel comfortable. So I'll also try other shortcuts. I also need to explore using an external editor, I've avoided it because I'm hitting F5 after virtually every edit. Trial and error plays a big part in my workflow. But I'd benefit from the superior features an external editor can offer. For example, simply changing the text or background colour would help keeping track of what code a difference(),union(), rotate(), etc is about to be operated on. Earlier today I did play with 'include <pipe.h>', but of course that merely pastes the text into the code *once.* I still think a simple feature of the sort I described could be helpful to complement the other tools. On Wed, 9 Feb 2022 at 18:29, Torsten Paul <Torsten.Paul@gmx.de> wrote: > I agree on what's said on using modules, but I'm not sure > that's what the original question is asking for. > > It sounds to me the feature that's been asked for is actually > an editor-only feature to type shortcuts. > > E.g. when writing Java code in Netbeans, I can type: > > sout<TAB> and that will expand to System.out.println(""); > with the cursor placed between the quotes. > > OpenSCAD has something similar, more targeting bigger > snippets of code via <Right Mouse Click> -> Insert Template. > > Having the shorter form that does that simpler text > replacement might still be useful in addition, e.g. with > the example given earlier it would: > > =tp<TAB> > > expand to the text > > Terry ... <email-address> > > replacing the =tp. > > ciao, > Torsten. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
TP
Torsten Paul
Wed, Feb 9, 2022 7:35 PM

On 09.02.22 20:30, Terry Pinnell wrote:

I still think a simple feature of the sort I described
could be helpful to complement the other tools.

That's the point. So far people have quite different
interpretation of what you've described.

That means there's no possibility to even say if it would
be added as feature in OpenSCAD. For that it needs to be
very clear how it would work from user perspective.

ciao,
Torsten.

On 09.02.22 20:30, Terry Pinnell wrote: > I still think a simple feature of the sort I described > could be helpful to complement the other tools. That's the point. So far people have quite different interpretation of what you've described. That means there's no possibility to even say if it would be added as feature in OpenSCAD. For that it needs to be very clear how it would work from user perspective. ciao, Torsten.
FS
FF Systems
Wed, Feb 9, 2022 7:37 PM

Well, my vote is for Notepad++.  The column copy/insert feature is VERY
handy.

(It is important to note that this is in NO way related to Windows Notepad)

Any programmer's text editor will do what you need, however.

Once the source is open in openSCAD, you just save it from the external
editor (there is a config option in openSCAD to auto load, but this is the
default, so I've never adjusted it) and then openSCAD will reload it
automatically. Works just fine by my accounting.

On Wed, Feb 9, 2022 at 1:31 PM Terry Pinnell terrypingm@gmail.com wrote:

Thanks all. OK, I'll get stuck into using modules. I expect it will take a
while before I really feel comfortable. So I'll also try other shortcuts.

I also need to explore using an external editor, I've avoided it because
I'm hitting F5 after virtually every edit. Trial and error plays a big part
in my workflow. But I'd benefit from the superior features an external
editor can offer. For example, simply changing the text or background
colour would help keeping track of what code a difference(),union(),
rotate(), etc is about to be operated on.

Earlier today I did play with 'include <pipe.h>', but of course that
merely pastes the text into the code once.

I still think a simple feature of the sort I described could be helpful to
complement the other tools.

On Wed, 9 Feb 2022 at 18:29, Torsten Paul Torsten.Paul@gmx.de wrote:

I agree on what's said on using modules, but I'm not sure
that's what the original question is asking for.

It sounds to me the feature that's been asked for is actually
an editor-only feature to type shortcuts.

E.g. when writing Java code in Netbeans, I can type:

sout<TAB> and that will expand to System.out.println("");
with the cursor placed between the quotes.

OpenSCAD has something similar, more targeting bigger
snippets of code via <Right Mouse Click> -> Insert Template.

Having the shorter form that does that simpler text
replacement might still be useful in addition, e.g. with
the example given earlier it would:

=tp<TAB>

expand to the text

Terry ... <email-address>

replacing the =tp.

ciao,
Torsten.


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

Well, my vote is for Notepad++. The column copy/insert feature is VERY handy. (It is important to note that this is in NO way related to Windows Notepad) Any programmer's text editor will do what you need, however. Once the source is open in openSCAD, you just save it from the external editor (there is a config option in openSCAD to auto load, but this is the default, so I've never adjusted it) and then openSCAD will reload it automatically. Works just fine by my accounting. On Wed, Feb 9, 2022 at 1:31 PM Terry Pinnell <terrypingm@gmail.com> wrote: > Thanks all. OK, I'll get stuck into using modules. I expect it will take a > while before I really feel comfortable. So I'll also try other shortcuts. > > I also need to explore using an external editor, I've avoided it because > I'm hitting F5 after virtually every edit. Trial and error plays a big part > in my workflow. But I'd benefit from the superior features an external > editor can offer. For example, simply changing the text or background > colour would help keeping track of what code a difference(),union(), > rotate(), etc is about to be operated on. > > Earlier today I did play with 'include <pipe.h>', but of course that > merely pastes the text into the code *once.* > > I still think a simple feature of the sort I described could be helpful to > complement the other tools. > > On Wed, 9 Feb 2022 at 18:29, Torsten Paul <Torsten.Paul@gmx.de> wrote: > >> I agree on what's said on using modules, but I'm not sure >> that's what the original question is asking for. >> >> It sounds to me the feature that's been asked for is actually >> an editor-only feature to type shortcuts. >> >> E.g. when writing Java code in Netbeans, I can type: >> >> sout<TAB> and that will expand to System.out.println(""); >> with the cursor placed between the quotes. >> >> OpenSCAD has something similar, more targeting bigger >> snippets of code via <Right Mouse Click> -> Insert Template. >> >> Having the shorter form that does that simpler text >> replacement might still be useful in addition, e.g. with >> the example given earlier it would: >> >> =tp<TAB> >> >> expand to the text >> >> Terry ... <email-address> >> >> replacing the =tp. >> >> ciao, >> Torsten. >> _______________________________________________ >> 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
Wed, Feb 9, 2022 8:14 PM

A text-expander system can do this too, if you like. Here's a random
article I found that gives some. I've never used any of them, so take this
as you will: https://techwiser.com/text-expander-apps-for-windows/

On Wed, Feb 9, 2022 at 1:38 PM FF Systems joeh@rollanet.org wrote:

Well, my vote is for Notepad++.  The column copy/insert feature is VERY
handy.

(It is important to note that this is in NO way related to Windows Notepad)

Any programmer's text editor will do what you need, however.

Once the source is open in openSCAD, you just save it from the external
editor (there is a config option in openSCAD to auto load, but this is the
default, so I've never adjusted it) and then openSCAD will reload it
automatically. Works just fine by my accounting.

On Wed, Feb 9, 2022 at 1:31 PM Terry Pinnell terrypingm@gmail.com wrote:

Thanks all. OK, I'll get stuck into using modules. I expect it will take
a while before I really feel comfortable. So I'll also try other shortcuts.

I also need to explore using an external editor, I've avoided it because
I'm hitting F5 after virtually every edit. Trial and error plays a big part
in my workflow. But I'd benefit from the superior features an external
editor can offer. For example, simply changing the text or background
colour would help keeping track of what code a difference(),union(),
rotate(), etc is about to be operated on.

Earlier today I did play with 'include <pipe.h>', but of course that
merely pastes the text into the code once.

I still think a simple feature of the sort I described could be helpful
to complement the other tools.

On Wed, 9 Feb 2022 at 18:29, Torsten Paul Torsten.Paul@gmx.de wrote:

I agree on what's said on using modules, but I'm not sure
that's what the original question is asking for.

It sounds to me the feature that's been asked for is actually
an editor-only feature to type shortcuts.

E.g. when writing Java code in Netbeans, I can type:

sout<TAB> and that will expand to System.out.println("");
with the cursor placed between the quotes.

OpenSCAD has something similar, more targeting bigger
snippets of code via <Right Mouse Click> -> Insert Template.

Having the shorter form that does that simpler text
replacement might still be useful in addition, e.g. with
the example given earlier it would:

=tp<TAB>

expand to the text

Terry ... <email-address>

replacing the =tp.

ciao,
Torsten.


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


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

A text-expander system can do this too, if you like. Here's a random article I found that gives some. I've never used any of them, so take this as you will: https://techwiser.com/text-expander-apps-for-windows/ On Wed, Feb 9, 2022 at 1:38 PM FF Systems <joeh@rollanet.org> wrote: > Well, my vote is for Notepad++. The column copy/insert feature is VERY > handy. > > (It is important to note that this is in NO way related to Windows Notepad) > > Any programmer's text editor will do what you need, however. > > Once the source is open in openSCAD, you just save it from the external > editor (there is a config option in openSCAD to auto load, but this is the > default, so I've never adjusted it) and then openSCAD will reload it > automatically. Works just fine by my accounting. > > On Wed, Feb 9, 2022 at 1:31 PM Terry Pinnell <terrypingm@gmail.com> wrote: > >> Thanks all. OK, I'll get stuck into using modules. I expect it will take >> a while before I really feel comfortable. So I'll also try other shortcuts. >> >> I also need to explore using an external editor, I've avoided it because >> I'm hitting F5 after virtually every edit. Trial and error plays a big part >> in my workflow. But I'd benefit from the superior features an external >> editor can offer. For example, simply changing the text or background >> colour would help keeping track of what code a difference(),union(), >> rotate(), etc is about to be operated on. >> >> Earlier today I did play with 'include <pipe.h>', but of course that >> merely pastes the text into the code *once.* >> >> I still think a simple feature of the sort I described could be helpful >> to complement the other tools. >> >> On Wed, 9 Feb 2022 at 18:29, Torsten Paul <Torsten.Paul@gmx.de> wrote: >> >>> I agree on what's said on using modules, but I'm not sure >>> that's what the original question is asking for. >>> >>> It sounds to me the feature that's been asked for is actually >>> an editor-only feature to type shortcuts. >>> >>> E.g. when writing Java code in Netbeans, I can type: >>> >>> sout<TAB> and that will expand to System.out.println(""); >>> with the cursor placed between the quotes. >>> >>> OpenSCAD has something similar, more targeting bigger >>> snippets of code via <Right Mouse Click> -> Insert Template. >>> >>> Having the shorter form that does that simpler text >>> replacement might still be useful in addition, e.g. with >>> the example given earlier it would: >>> >>> =tp<TAB> >>> >>> expand to the text >>> >>> Terry ... <email-address> >>> >>> replacing the =tp. >>> >>> ciao, >>> Torsten. >>> _______________________________________________ >>> 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 >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
DS
David Schooley
Wed, Feb 9, 2022 10:12 PM

Since multi-color printing came up recently without me following the conversation too closely…

Modules can make multi-color printing easy. The part to be done in color #1 is one module and the part done in color #2 is another module. Part #2 is subtracted from part #1 to get the stl for the first color, and part #2 is used by itself to get the stl for the second color.

Trivial example:

————————————————————

module draw_color_one() {
color("green") difference() {
cube([10, 10, 10]);
draw_color_two();
}
}

module draw_color_two() {
color("red") translate([0, 0, 5]) cylinder(r = 3, h = 8, $fn=60);
}

draw_color_one(); // Make an stl or 3mf with just this to get the file for the first color

draw_color_two(); // and make another stl or 3mf with just this to get the file for the second color.

————————————————————

On Feb 9, 2022, at 12:15 PM, FF Systems joeh@rollanet.org wrote:

I echo what M^2 says.  I was reluctant to use modules at first, but now I use them freely.  It really is EXACTLY what you originally asked for.  PLUS, you can pass parameters when you get used to the syntax.  The modules then start to become more generic and you can customize them based on how you want to use a particular instance.  For example, I have a countersink shape that I use to create countersinks in difference() stacks (BOSL2 and other libraries likely have similar constructs, but I created my own).  I can pass a parameter to set the screw size for the CS.  Once I had coded the module to produce the right size based on the passed parameter (a "2" or "4", etc...) I can now reuse the object and set it to the size I want on the fly.

Coding in openSCAD is just like coding for computer programs, you can't read your way to expertise, you have to CODE your way to it.

PS: Compiler MACROS are constructs like M^2 alluded towards... they are text replacements made by the compiler/assembler for computer programs.  They can increase code speed because the overhead of calling the function/subroutine is eliminated (useful for interrupts or looping constructs).  In openSCAD, there is no such benefit to be reaped, so the practice has no corollary.  Thus, modules() are what you have here.

On Wed, Feb 9, 2022 at 11:59 AM Michael Möller <private2michael@gmail.com mailto:private2michael@gmail.com> wrote:
" any future use of the string ‘shaftxyz’ (apart from this specific statement) would effectively replace that code."

That is called a text macro, i.e. it is something an editor does. You can use ANY editor to create the OpenSCAD code, and then use OpenSCAD to compile/visualise it. https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_an_external_Editor_with_OpenSCAD https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_an_external_Editor_with_OpenSCAD

Or you write your code using "shaftxyz", then use Ctrl-Shift-F and ask to replace all "shaftxyz" occurrences with "cylinder( ..." in your code.

Either way - using a text editor/replace - from then onwards the "shaftxyz" text is no longer there. There is the (possibly complicated) "cylinder( ..." code.

Which is why the modules is better. There will always be "shaftxyz()" in your code. Yes, you need to type an extra "()" after it, but otherwise that does what you want.

"Oh but I first have to write the module" - you say (perhaps. Well, you had to write the text macro or the replacement string, too, so you are no worse off, AND it is in the code, instead of hidden in an external text editor. Also note you do not have to have parameters. Even if your module has parameters, they can be made optional by giving them a default value so the calling code can be "shaftxyz()" for the standard shaft, and "shaftxyz(L=100)" for an exceptional long one.

I really have a hard time understanding a reason for NOT using modules. As opposed to an executable program you can use modules as much as you like, and it will have immeasurably little time effect on your compilation. It probably even will speed your rendering, due to caching (Your Mileage May Vary)

Msquare

NB: "Getting better at modules" you're only going to get better by actually using them. Simplistic "text substitution" to start with, and then gradually work your way up

On Wed, 9 Feb 2022 at 14:52, terrypingm@gmail.com mailto:terrypingm@gmail.com <terrypingm@gmail.com mailto:terrypingm@gmail.com> wrote:
Thanks nop head. Although I understand the greater fexibility of modules, I naively had in mind something much simpler. While still editing my code, say that subtraction on my two cylinders is done. I’d like to bracket that code, place my cursor at the start and type something like ‘Define shaftxyz:’ So that any future use of the string ‘shaftxyz’ (apart from this specific statement) would effectively replace that code. No decisions about future use, no decision whether parameters needed and if so what to call them. Just like my abbreviation ‘=tp’ to type my full name and address.

--
Terry

On 9 Feb 2022, at 12:53, nop head <nop.head@gmail.com mailto:nop.head@gmail.com> wrote:


Yes, make it a module called shaft and use shaft().

On Wed, 9 Feb 2022 at 12:50, Terry Pinnell <terrypingm@gmail.com mailto:terrypingm@gmail.com> wrote:
Probably an embarrassingly obvious answer, but..

When building a model, say a shaft for a spindle, suppose I start with subtracting a smaller cylinder from another. Developing that, the code can soon get quite messy. Differences of differences and the like. Is there a simple way to name my model, say 'Shaft', and then use that name in all further editing?

--
Terry


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


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


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


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


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

Since multi-color printing came up recently without me following the conversation too closely… Modules can make multi-color printing easy. The part to be done in color #1 is one module and the part done in color #2 is another module. Part #2 is subtracted from part #1 to get the stl for the first color, and part #2 is used by itself to get the stl for the second color. Trivial example: ———————————————————— module draw_color_one() { color("green") difference() { cube([10, 10, 10]); draw_color_two(); } } module draw_color_two() { color("red") translate([0, 0, 5]) cylinder(r = 3, h = 8, $fn=60); } draw_color_one(); // Make an stl or 3mf with just this to get the file for the first color draw_color_two(); // and make another stl or 3mf with just this to get the file for the second color. ———————————————————— > On Feb 9, 2022, at 12:15 PM, FF Systems <joeh@rollanet.org> wrote: > > I echo what M^2 says. I was reluctant to use modules at first, but now I use them freely. It really is EXACTLY what you originally asked for. PLUS, you can pass parameters when you get used to the syntax. The modules then start to become more generic and you can customize them based on how you want to use a particular instance. For example, I have a countersink shape that I use to create countersinks in difference() stacks (BOSL2 and other libraries likely have similar constructs, but I created my own). I can pass a parameter to set the screw size for the CS. Once I had coded the module to produce the right size based on the passed parameter (a "2" or "4", etc...) I can now reuse the object and set it to the size I want on the fly. > > Coding in openSCAD is just like coding for computer programs, you can't read your way to expertise, you have to CODE your way to it. > > PS: Compiler MACROS are constructs like M^2 alluded towards... they are text replacements made by the compiler/assembler for computer programs. They can increase code speed because the overhead of calling the function/subroutine is eliminated (useful for interrupts or looping constructs). In openSCAD, there is no such benefit to be reaped, so the practice has no corollary. Thus, modules() are what you have here. > > > On Wed, Feb 9, 2022 at 11:59 AM Michael Möller <private2michael@gmail.com <mailto:private2michael@gmail.com>> wrote: > " any future use of the string ‘shaftxyz’ (apart from this specific statement) would effectively replace that code." > > That is called a text macro, i.e. it is something an editor does. You can use ANY editor to create the OpenSCAD code, and then use OpenSCAD to compile/visualise it. https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_an_external_Editor_with_OpenSCAD <https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_an_external_Editor_with_OpenSCAD> > > Or you write your code using "shaftxyz", then use Ctrl-Shift-F and ask to replace all "shaftxyz" occurrences with "cylinder( ..." in your code. > > Either way - using a text editor/replace - from then onwards the "shaftxyz" text is no longer there. There is the (possibly complicated) "cylinder( ..." code. > > Which is why the modules is better. There will always be "shaftxyz()" in your code. Yes, you need to type an extra "()" after it, but otherwise that does what you want. > > "Oh but I first have to write the module" - you say (perhaps. Well, you had to write the text macro or the replacement string, too, so you are no worse off, AND it is in the code, instead of hidden in an external text editor. Also note you do not have to have parameters. Even if your module has parameters, they can be made optional by giving them a default value so the calling code can be "shaftxyz()" for the standard shaft, and "shaftxyz(L=100)" for an exceptional long one. > > I really have a hard time understanding a reason for NOT using modules. As opposed to an executable program you can use modules as much as you like, and it will have immeasurably little time effect on your compilation. It probably even will speed your rendering, due to caching (Your Mileage May Vary) > > Msquare > > NB: "Getting better at modules" you're only going to get better by actually using them. Simplistic "text substitution" to start with, and then gradually work your way up > > > On Wed, 9 Feb 2022 at 14:52, terrypingm@gmail.com <mailto:terrypingm@gmail.com> <terrypingm@gmail.com <mailto:terrypingm@gmail.com>> wrote: > Thanks nop head. Although I understand the greater fexibility of modules, I naively had in mind something much simpler. While still editing my code, say that subtraction on my two cylinders is done. I’d like to bracket that code, place my cursor at the start and type something like ‘Define shaftxyz:’ So that any future use of the string ‘shaftxyz’ (apart from this specific statement) would effectively replace that code. No decisions about future use, no decision whether parameters needed and if so what to call them. Just like my abbreviation ‘=tp’ to type my full name and address. > > -- > Terry > >> On 9 Feb 2022, at 12:53, nop head <nop.head@gmail.com <mailto:nop.head@gmail.com>> wrote: >> >>  >> Yes, make it a module called shaft and use shaft(). >> >> On Wed, 9 Feb 2022 at 12:50, Terry Pinnell <terrypingm@gmail.com <mailto:terrypingm@gmail.com>> wrote: >> Probably an embarrassingly obvious answer, but.. >> >> When building a model, say a shaft for a spindle, suppose I start with subtracting a smaller cylinder from another. Developing that, the code can soon get quite messy. Differences of differences and the like. Is there a simple way to name my model, say 'Shaft', and then use that name in all further editing? >> >> -- >> Terry >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
T
terrypingm@gmail.com
Wed, Feb 9, 2022 10:43 PM

Yes, that’s the sort of thing I can do with Macro Express Pro. But like all approaches of this genre it nets down to

  1. Copying the code (the ‘chunk’ of my OP)
  2. Opening the external tool and pasting it in
  3. Assigning a brief name to it (and enduring it's unique)
  4. Returning to OpenSCAD
  5. Using that name to automatically type the original chunk

Which is not what I described. I want
A. The abbreviation to be created in OpenSCAD
B.  Used as an alias for the code, not to reproduce it.

On 9 Feb 2022, at 20:15, Father Horton fatherhorton@gmail.com wrote:


A text-expander system can do this too, if you like. Here's a random article I found that gives some. I've never used any of them, so take this as you will: https://techwiser.com/text-expander-apps-for-windows/

On Wed, Feb 9, 2022 at 1:38 PM FF Systems joeh@rollanet.org wrote:
Well, my vote is for Notepad++.  The column copy/insert feature is VERY handy.

(It is important to note that this is in NO way related to Windows Notepad)

Any programmer's text editor will do what you need, however.

Once the source is open in openSCAD, you just save it from the external editor (there is a config option in openSCAD to auto load, but this is the default, so I've never adjusted it) and then openSCAD will reload it automatically. Works just fine by my accounting.

On Wed, Feb 9, 2022 at 1:31 PM Terry Pinnell terrypingm@gmail.com wrote:
Thanks all. OK, I'll get stuck into using modules. I expect it will take a while before I really feel comfortable. So I'll also try other shortcuts.

I also need to explore using an external editor, I've avoided it because I'm hitting F5 after virtually every edit. Trial and error plays a big part in my workflow. But I'd benefit from the superior features an external editor can offer. For example, simply changing the text or background colour would help keeping track of what code a difference(),union(), rotate(), etc is about to be operated on.

Earlier today I did play with 'include <pipe.h>', but of course that merely pastes the text into the code once.

I still think a simple feature of the sort I described could be helpful to complement the other tools.

On Wed, 9 Feb 2022 at 18:29, Torsten Paul Torsten.Paul@gmx.de wrote:
I agree on what's said on using modules, but I'm not sure
that's what the original question is asking for.

It sounds to me the feature that's been asked for is actually
an editor-only feature to type shortcuts.

E.g. when writing Java code in Netbeans, I can type:

sout<TAB> and that will expand to System.out.println("");
with the cursor placed between the quotes.

OpenSCAD has something similar, more targeting bigger
snippets of code via <Right Mouse Click> -> Insert Template.

Having the shorter form that does that simpler text
replacement might still be useful in addition, e.g. with
the example given earlier it would:

=tp<TAB>

expand to the text

Terry ... <email-address>

replacing the =tp.

ciao,
Torsten.


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


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

Yes, that’s the sort of thing I can do with Macro Express Pro. But like all approaches of this genre it nets down to 1. Copying the code (the ‘chunk’ of my OP) 2. Opening the external tool and pasting it in 3. Assigning a brief name to it (and enduring it's unique) 4. Returning to OpenSCAD 5. Using that name to automatically type the original chunk Which is not what I described. I want A. The abbreviation to be created in OpenSCAD B. Used as an alias for the code, not to reproduce it. > On 9 Feb 2022, at 20:15, Father Horton <fatherhorton@gmail.com> wrote: > >  > A text-expander system can do this too, if you like. Here's a random article I found that gives some. I've never used any of them, so take this as you will: https://techwiser.com/text-expander-apps-for-windows/ > >> On Wed, Feb 9, 2022 at 1:38 PM FF Systems <joeh@rollanet.org> wrote: >> Well, my vote is for Notepad++. The column copy/insert feature is VERY handy. >> >> (It is important to note that this is in NO way related to Windows Notepad) >> >> Any programmer's text editor will do what you need, however. >> >> Once the source is open in openSCAD, you just save it from the external editor (there is a config option in openSCAD to auto load, but this is the default, so I've never adjusted it) and then openSCAD will reload it automatically. Works just fine by my accounting. >> >>> On Wed, Feb 9, 2022 at 1:31 PM Terry Pinnell <terrypingm@gmail.com> wrote: >>> Thanks all. OK, I'll get stuck into using modules. I expect it will take a while before I really feel comfortable. So I'll also try other shortcuts. >>> >>> I also need to explore using an external editor, I've avoided it because I'm hitting F5 after virtually every edit. Trial and error plays a big part in my workflow. But I'd benefit from the superior features an external editor can offer. For example, simply changing the text or background colour would help keeping track of what code a difference(),union(), rotate(), etc is about to be operated on. >>> >>> Earlier today I did play with 'include <pipe.h>', but of course that merely pastes the text into the code once. >>> >>> I still think a simple feature of the sort I described could be helpful to complement the other tools. >>> >>>> On Wed, 9 Feb 2022 at 18:29, Torsten Paul <Torsten.Paul@gmx.de> wrote: >>>> I agree on what's said on using modules, but I'm not sure >>>> that's what the original question is asking for. >>>> >>>> It sounds to me the feature that's been asked for is actually >>>> an editor-only feature to type shortcuts. >>>> >>>> E.g. when writing Java code in Netbeans, I can type: >>>> >>>> sout<TAB> and that will expand to System.out.println(""); >>>> with the cursor placed between the quotes. >>>> >>>> OpenSCAD has something similar, more targeting bigger >>>> snippets of code via <Right Mouse Click> -> Insert Template. >>>> >>>> Having the shorter form that does that simpler text >>>> replacement might still be useful in addition, e.g. with >>>> the example given earlier it would: >>>> >>>> =tp<TAB> >>>> >>>> expand to the text >>>> >>>> Terry ... <email-address> >>>> >>>> replacing the =tp. >>>> >>>> ciao, >>>> Torsten. >>>> _______________________________________________ >>>> 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 >> _______________________________________________ >> 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
J
jon
Wed, Feb 9, 2022 10:49 PM

I keep thinking that you want a module().  I use them all the time, and
they are trivial to write.

On 2/9/2022 5:43 PM, terrypingm@gmail.com wrote:

Yes, that’s the sort of thing I can do with Macro Express Pro. But
like all approaches of this genre it nets down to

  1. Copying the code (the ‘chunk’ of my OP)
  2. Opening the external tool and pasting it in
  3. Assigning a brief name to it (and enduring it's unique)
  4. Returning to OpenSCAD
  5. Using that name to automatically type the original chunk

Which is not what I described. I want
A. The abbreviation to be created in OpenSCAD
B.  Used as an alias for the code, not to reproduce it.

I keep thinking that you want a module().  I use them all the time, and they are trivial to write. On 2/9/2022 5:43 PM, terrypingm@gmail.com wrote: > Yes, that’s the sort of thing I can do with Macro Express Pro. But > like all approaches of this genre it nets down to > 1. Copying the code (the ‘chunk’ of my OP) > 2. Opening the external tool and pasting it in > 3. Assigning a brief name to it (and enduring it's unique) > 4. Returning to OpenSCAD > 5. Using that name to automatically type the original chunk > > Which is not what I described. I want > A. The abbreviation to be created in OpenSCAD > B.  Used as an alias for the code, not to reproduce it. > >