Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Render CSV data into png files for animation / video overlay via OpenSCAD
@echo off
if NOT [%2]==[] goto :doit
echo Usage:
echo %0 data.csv script.scad parameters
echo Where:
echo - data.csv is a csv file where each line corrisponds to a single frame to be produced in the PNG file
echo.
echo - script.scad is the script which will render the line of data into the PNG frame.
echo The script should parse the line of data and render a valid output
echo https://github.com/davidson16807/relativity.scad/blob/master/strings.scad
echo is very helpful. e.g. In OpenSCAD
echo include ^<strings.scad^>;
echo line = "1,2,3";
echo values = split(line,",");
echo translate([10,0,0]) text(values[1]);
echo function str2num(str, i=0, nb=0) = i == len(str) ? nb :
echo nb+str2num(str, i+1, search(str[i],"0123456789")[0]*pow(10,len(str)-i-1));
echo cube([str2num(values[2]),str2num(values[1]),str2num(values[0])]);
echo.
echo - parameters are whatever else you want to feed to OpenSCAD
echo e.g. "--camera=0,0,0, 0,0,0, 100"
goto :done
:doit
pushd %PROGRAMFILES%\OpenSCAD\
REM we must work from the program folder because:
REM https://github.com/openscad/openscad/issues/1309
REM and so we reference files relative to the batch via %~dp0\
set /a c=0
REM start counting output files
setlocal ENABLEDELAYEDEXPANSION
FOR /F "tokens=1" %%i in (%~dp0\%1) do (
"openscad.exe" %~dp0\%2 -D "line=\"%%i\"" -o %~dp0\!c!.png %3
set /a c=c+1
)
endlocal
popd
:done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.