New follower and question about script flow

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

New follower and question about script flow

Baxsie
It seems to me that OpenSCAD only has a few (<100 ?) statements.

Each of those could be wrapped in a C (or python or any other "real" language) function that simply evaluated the the C variables and appended the line to the OpenSCAD output file.

So in C (example not compiled, just jotted int he e-mail program):

//======================================
FILE
  *output;

function OSC_translate(double x,double  y,double z)
  {
  fprintf(output,"translate([",%11.5f,",",%11.5f,",",%11.5f,"])",
             x,y,z);
  }
function OSC_cube(double x,double  y,double z, int facets=0)
  {
  if(facets)
    fprintf(output,"cube([",%11.5f,",",%11.5f,",",%11.5f,"])",
             x,y,z);
  else
    fprintf(output,"cube([",%11.5f,",",%11.5f,",",%11.5f,"],$fn=",%d,")",
             x,y,z,facets);
  }
function OSC_EOL(double x,double  y,double z)
  {
  fprintf(output,";\cr\lf"");
  }

void main(void)
  {
  fopen(output,"w","output.scad");
  int
    xpos;
  xpos=0;
  for (int i=1;i<=3;i++)
    {
    OSC_translate(xpos,0,0);
    OSC_cube(i,i,i);
    OSC_EOL();
    xpos+=i+1;
    }
//======================================

would create these statements in the OpenSCAD output file:

translate([0,0,0]) cube([1,1,1]);
translate([2,0,0]) cube([2,2,2]);
translate([5,0,0]) cube([3,3,3]);

All the benefits of a high-level language, and all the benefits of OpenSCAD, but none of the limitations like the OpenSCAD pseudo language like its "variables".

The ugliest thing I see about this is the wait for the C build and execute cycle every time you want to view output,

Maybe with python (which I do not know) the python script equivalent of the above functions could run be set to run automatically on a save from editor, then OpenSCAD set to "Automatic Reload and Compile", so a "Ctrl+S" in the editor would cascade through to an updated OpenSCAD preview.

Just some thoughts.

Some OpenSCAD things I have made:

Reply | Threaded
Open this post in threaded view
|

Re: New follower and question about script flow

Giles Bathgate-2
On Sat, 2011-04-09 at 09:50 -0700, Brent Crosby wrote:

> Each of those could be wrapped in a C (or python or any other "real"
> language) function that simply evaluated the the C variables and
> appended the line to the OpenSCAD output file.

This is what efforts like pySCAD and SolidPython are doing.

My approach with RapCAD was to make a procedural scripting language that
is backwards compatible with openscad.

Regards

Giles