openscad/openscad — pull request #845 by carlosgs (2014-06-23 16:36:31+00:00)
Title: Added file writting functionality to echo

This implements file writing functionality to the echo function. Example:

echo2file_demo.scad
```
echo("test");
echo(tofile="echo2file_demo_autogenerated.txt","test1\n",append=false);
echo(tofile="echo2file_demo_autogenerated.txt","test2\n");
echo(tofile="echo2file_demo_autogenerated.txt","\n");

a = 42;
echo(tofile="echo2file_demo_autogenerated.txt",str("a=",42,";"));
```

Console output
```
ECHO: "test"
WRITING TO FILE echo2file_demo_autogenerated.txt
WRITING: test1

APPENDING TO FILE echo2file_demo_autogenerated.txt
WRITING: test2

APPENDING TO FILE echo2file_demo_autogenerated.txt
WRITING:

APPENDING TO FILE echo2file_demo_autogenerated.txt
WRITING: a=42;
```

echo2file_demo_autogenerated.txt
```
test1
test2

a=42;
```

Original message ( https://github.com/openscad/openscad/issues/844 )
```
I think "echo" needs to be able to write values to text files. This would be very useful in order to automatically generate BOMs and debug measurements and information to files.

But the implication that excites me more is the fact that it would open the possibility to write other ".scad" files:
After reading all the discussion involving "defining global variables from local scopes", "retrieving values from modules", etc, I think adding the capability to write text files could provide a good solution to situations that require such tasks. The point is that using "echo" we could write configuration ".scad" files in order to update variables in the main code automatically, thus being able to incorporate results from the inside of sub-tree calls.
It would not be the cleanest solution, but probably one of the simplest ways to implement this kind of functionality into OpenScad with minimal effort.
```