Occasionally there might be a need to dump the echo output to a file. For
example, "automatically generate BOMs and debug measurements and information
to files." as described by carlosgs here
https://github.com/openscad/openscad/pull/845 [1], or in the application
of my doctest lib ( here https://github.com/runsun/openscad_doctest ).
Unfortunately OpenScad can't do that, and there seems to be no plan
(according to [1]) for that feature.
But there are ways to get around it:
(1) You can dump echo output to a file under command line (Linux):
openscad <scad_file> -o dump.stl -D "<commands_to_execute>" 2>
<output_file>
For example, one of my uses looks like this:
time openscad mylib.scad -o dump.stl -D "FORHTML=true;runtest()" 2>
mylib_api.htm
(2) The above approach works, but every echo( ) inserts "ECHO: " to the
beginning of output and a trailing " in the end. It is inconvenient to have
multiple execution-unrelated "ECHO: " in an output file, especially if the
main purpose of dumping to a file is for further automatic processing.
The easiest way for OpenSCAD to solve this is to have an option to suppress
the display of "ECHO: ".
But, before that being considered a feature to add, we can use the following
simple python script. Note that: (1) It is coded on Linux and hasn't been
tested on Win or Mac; (2) It assumes that /all echo output are strings/. It
can be used this way:
time python runscad.py mylib.scad "FORHTML=true;runtest()" mylib_api.htm
############################## ## runscad.py## Run an openscad file and
dump the echo output to a file## >>> python runscad.py <scad_file>
"<commands_to_execute>" <output_file>## Like:## >>> python
runscad.py mylib.scad "FORHTML=true;runtest()" mylib_api.htm## by Runsun
Pan (2015.5.1)##############################
import sys, os, reif len(sys.argv)<4: print
'''# runscad.py## Not enough arguments. Required 3 arguments:## python
runscad.py <scad_file> "<command(s)>" <output_file>## For
example:## python runscad.py myprog.scad "FORHTML=true;MODE=10;run()"
tests.html'''
else: cmd =
'openscad %s -o dump.stl -D "%s" 2> %s'
% tuple(sys.argv[1:]) os.system( cmd ) output_file= sys.argv[3]
lines = open( output_file, 'r').readlines()
ptn = re.compile(r'ECHO: \"|"$') for i,line in enumerate(lines):
lines[i] = re.sub( ptn,'', line)
object is empty."
open( output_file, 'w').write( '\n'.join( lines[:-1] )
)##############################
$ Runsun Pan, PhD
$ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse )
$ -- hash parameter model: here , here
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
--
View this message in context: http://forum.openscad.org/Sharing-Dump-echo-output-to-a-file-tp12529.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
On Fri, May 1, 2015 at 9:58 AM, runsun runsun@gmail.com wrote:
openscad <scad_file> -o dump.stl -D "<commands_to_execute>" 2>
<output_file>
how about this?
openscad testthingie.scad -o junk.stl 2>&1 >/dev/null | sed 's/ECHO: "//' |
sed 's/"$//' > outfile
Jerry
--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer
The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".- Isaac. Asimov
I
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous
If writing good code requires very little comments, then writing really
excellent code requires no comments at all!- Ken Thompson
Hi Jerry, that's a much shorter one :)
In fact I started this with a sed version, too. Not as elegant as yours but
works. I then move on to the python one 'cos I thought it'd be
cross-platform.
Nonetheless, will steal your idea and make an alias outta it. Thx.
jdawgaz wrote
openscad testthingie.scad -o junk.stl 2>&1 >/dev/null | sed 's/ECHO: "//'
| sed 's/"$//' > outfile
Jerry
$ Runsun Pan, PhD
$ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse )
$ -- hash parameter model: here , here
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
--
View this message in context: http://forum.openscad.org/Sharing-Dump-echo-output-to-a-file-tp12529p12533.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
no problemo.
the python one would work in windoze.
don't get me wrong, I love python too. And ruby.
Before retiring, I did 5 years of every day python work. grew to love it.
Now I play with my raspberry pi and python (and ruby)
Jerry
--
Extra Ham Operator: K7AZJ
Registered Linux User: 275424
Raspberry Pi and Arduino developer
The most exciting phrase to hear in science - the one that heralds new
discoveries - is not "Eureka!" but "That's funny...".- Isaac. Asimov
I
*f you give someone a program, you will frustrate them for a day; if you
teach them how to program, you will frustrate them for a lifetime. *-
Anonymous
If writing good code requires very little comments, then writing really
excellent code requires no comments at all!- Ken Thompson
On Fri, May 1, 2015 at 10:55 AM, runsun runsun@gmail.com wrote:
Hi Jerry, that's a much shorter one :)
In fact I started this with a sed version, too. Not as elegant as yours but
works. I then move on to the python one 'cos I thought it'd be
cross-platform.
Nonetheless, will steal your idea and make an alias outta it. Thx.
jdawgaz wrote
openscad testthingie.scad -o junk.stl 2>&1 >/dev/null | sed 's/ECHO: "//'
| sed 's/"$//' > outfile
Jerry
$ Runsun Pan, PhD
$ -- OpenScad_DocTest: doc and unit test ( Github , Thingiverse )
$ -- hash parameter model: here , here
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
--
View this message in context:
http://forum.openscad.org/Sharing-Dump-echo-output-to-a-file-tp12529p12533.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org