Weird behaviour of commandline parameters

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

Weird behaviour of commandline parameters

janek

Hi all,

I am generating a set of tiles and I am using the (windows) commandline to do it. My typical cmd command is:

"c:\Program Files\OpenSCAD\openscad.com" -o stl\tile_6_3.stl -D "x=6" -D "y=3" cmdline_tile.scad

The cmdline_tile.scad file contains this code:

$fn = 30;
use <tile_module.scad>;
// dQ
midHeight = 38;
slopeN = [-95 / 12 * y, -57 / 12 * x, 32];
tile (slopeNh = midHeight);

And this produces an error:

WARNING: Ignoring unknown variable 'y', in file cmdline_tile.scad, line 6.
WARNING: undefined operation (number * undefined) in file cmdline_tile.scad, line 6
WARNING: Ignoring unknown variable 'x', in file cmdline_tile.scad, line 6.
WARNING: undefined operation (number * undefined) in file cmdline_tile.scad, line 6

And of course the result is empty...

If I add echo before the slopeN = […] assignment, the variables show themselves to be existent:

echo (x=x, y=y);

which produces this output line:

ECHO: x = 6, y = 3

again followed by the error claiming that variable 'y' is unknown etc.

What is, however, unexplainable for me, is the fact that the command on last line works, if I build the slope vector inline:

tile (n = [-95 12 * y, -57 / 12 * x, 32], h = midHeight);

This does not raise any warning and builds the expected tile. Why? And why I cannot build the vector and then use it?

(OK, I have a workaround now but I am not happy with the path)

Jan


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Weird behaviour of commandline parameters

MichaelAtOz
Administrator

'-D' adds that text to the end of the file (in memory).

 

so you get this

 

$fn = 30;

use <tile_module.scad>;

// dQ

midHeight = 38;

slopeN = [-95 / 12 * y, -57 / 12 * x, 32];

tile (slopeN, h = midHeight);

x=6;y=3;

 

Try that in the GUI

 

The magic source is

 

$fn = 30;

use <tile_module.scad>;

// dQ

midHeight = 38;

x=0; y=0;

slopeN = [-95 / 12 * y, -57 / 12 * x, 32];

tile (slopeN, h = midHeight);

x=6;y=3;

 

If you want to know why, ask, but I'll answer tomorrow, I have a glass of red calling to me...

 

 


From: Discuss [mailto:[hidden email]] On Behalf Of Jan Koupil
Sent: Fri, 14 Aug 2020 17:32
To: [hidden email]
Subject: [OpenSCAD] Weird behaviour of commandline parameters

 

Hi all,

I am generating a set of tiles and I am using the (windows) commandline to do it. My typical cmd command is:

"c:\Program Files\OpenSCAD\openscad.com" -o stl\tile_6_3.stl -D "x=6" -D "y=3" cmdline_tile.scad

The cmdline_tile.scad file contains this code:

$fn = 30;

use <tile_module.scad>;

 

// dQ

midHeight = 38;

slopeN = [-95 / 12 * y, -57 / 12 * x, 32];

tile (slopeN, h = midHeight);

And this produces an error:

WARNING: Ignoring unknown variable 'y', in file cmdline_tile.scad, line 6.
WARNING: undefined operation (number * undefined) in file cmdline_tile.scad, line 6
WARNING: Ignoring unknown variable 'x', in file cmdline_tile.scad, line 6.
WARNING: undefined operation (number * undefined) in file cmdline_tile.scad, line 6

And of course the result is empty...

If I add echo before the
slopeN = […] assignment, the variables show themselves to be existent:

echo (x=x, y=y);

which produces this output line:

ECHO: x = 6, y = 3

again followed by the error claiming that variable 'y' is unknown etc.

What is, however, unexplainable for me, is the fact that the command on last line works, if I build the slope vector inline:

tile (n = [-95 12 * y, -57 / 12 * x, 32], h = midHeight);

This does not raise any warning and builds the expected tile. Why? And why I cannot build the vector and then use it?

(OK, I have a workaround now but I am not happy with the path)

Jan

 


Virus-free. www.avg.com

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD Admin - email* me if you need anything, or if I've done something stupid...
* on the Forum, click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain;
to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.
tp3
Reply | Threaded
Open this post in threaded view
|

Re: Weird behaviour of commandline parameters

tp3
In reply to this post by janek
On 14.08.20 09:32, Jan Koupil wrote:
> This does not raise any warning and builds the expected tile.
> Why? And why I cannot build the vector and then use it?

Variables are initialized in order, modules called afterwards,
so if you want to use -D variables to calculate others, you
need to give them some initial value in the script before use.

a = 3;
b = a + 2;
echo(a, b);

openscad -Da=1 ...

ciao,
  Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten