I am a programmer and in that respect wanted to give a try to Openscad.

I spent about 1 day programming different objects in order to get used to it.I faced a problem while using it : Variables are set at compile, not at run time.In other words, you cannot change the value of a variable within a program.

What is the point calling them variables ?

I just feel like I lost my time trying it. In the user manual, they say that this makes the beauty of Openscad. My opinion is that it makes it useless to me.

Because of that, I believe there is nothing I can do faster in openscad than in my usual CAD software.

If you expect a programming language to actually support variables, don't loose too much time with openscad.If you are an openscad user and know a workaround, please tell me how.

OpenScad is a different kind of programming language than typical and I always have to re-calibrate my brain every time I need to program in it. That being said there are ways to get variable type behavior out of it, it just isn't going to be in a way that feels natural. The best way I think to see this is to look at some openscad code on thingiverse from things that can be customized. One of my latest projects has code that I kind of commented http://www.thingiverse.com/thing:1154214

PTMNBN="Printer that must not be named" - a heavily upgraded Replicator 2

jmpreuss wrote:OpenScad is a different kind of programming language than typical and I always have to re-calibrate my brain every time I need to program in it. That being said there are ways to get variable type behavior out of it, it just isn't going to be in a way that feels natural. The best way I think to see this is to look at some openscad code on thingiverse from things that can be customized. One of my latest projects has code that I kind of commented http://www.thingiverse.com/thing:1154214

Well yes... you don't use variable variables.

Customizer just allows to force the value of constant "variables".

What I'm trying to do is something like that, within a loop, on a if condition :variable = variable +1;

That is impossible as far I could see.

Geneb, I was not looking for a design tool, but I thought openscad could open new doors to me... it appears it cannot.I know Freecad, and don't like the user interface. I use Wings3D with great success, and OnShape on specific occasions.

I never heard of DesignSpark Mechanical. I'll have a look at it, since onshape is very intuitive, but the free plan is also very limited in term of data you can host.

enggmaug wrote:What I'm trying to do is something like that, within a loop, on a if condition :variable = variable +1;

Can you give an example of what you are trying to model that you want to use this if statement? It could be it's impossible with an if statement but it may be possible another way. I have programmed some pretty difficult models in OpenSCAD and not once have I run into something that was impossible, though maybe I had to do it very differently than I first thought.

PTMNBN="Printer that must not be named" - a heavily upgraded Replicator 2

enggmaug wrote:What I'm trying to do is something like that, within a loop, on a if condition :variable = variable +1;

Can you give an example of what you are trying to model that you want to use this if statement? It could be it's impossible with an if statement but it may be possible another way. I have programmed some pretty difficult models in OpenSCAD and not once have I run into something that was impossible, though maybe I had to do it very differently than I first thought.

Sure... as a learning exercice, I was trying to build a parametric wall, in which you specify the wall dimensions, and min Max dimension of stones in both length and height. The idea was to randomly choose integer dimensions for each stone, and build the wall up.

For example, all my stones are between 5 and 15 units in length, and between 5 and 15 units in height, only using integer values. That gives 11 different widths, 11 different heights, so 121 different stone types. Running twice the algorithm with a different seed value for the random would build 2 different walls, but with similar aspect.

The algorithm builds the wall sideways first, and then upways.

I use 2 intricated for loops for parsing the wall sideways and upways. I then use a if statement to check if a stone is present or not. If not, I create a new one.

enggmaug wrote:Sure... as a learning exercice, I was trying to build a parametric wall, in which you specify the wall dimensions, and min Max dimension of stones in both length and height. The idea was to randomly choose integer dimensions for each stone, and build the wall up.

For example, all my stones are between 5 and 15 units in length, and between 5 and 15 units in height, only using integer values. That gives 11 different widths, 11 different heights, so 121 different stone types. Running twice the algorithm with a different seed value for the random would build 2 different walls, but with similar aspect.

The algorithm builds the wall sideways first, and then upways.

I use 2 intricated for loops for parsing the wall sideways and upways. I then use a if statement to check if a stone is present or not. If not, I create a new one.

That was the basic idea...

That is an interesting exercise, one I can't answer off the top of my head. I'll give it some thought though it may be a few days as I am in the middle of getting my projects completed for the MRRF.

PTMNBN="Printer that must not be named" - a heavily upgraded Replicator 2

Renha wrote:How algo should act if stones should be between 20 and 20 both dimensions, and wall dimension should be 45x45?What if wall should be 19x19? 19x20?What about third dimension?

OpenSCAD is a nice programming language masquerading as an even nicer design tool. ￼ Do yourself a favor and don't check out either DesignSpark Mechanical or FreeCAD.

What?

Algo should act the same with your values.min max values given were just example. and anyway, they are parametric.

EDIT : I finally understood you question.

Algo should check if the remaining available part on the right is bigger or not than average value.If yes, normal behavior.If no, last stone takes all remaining space on the right.

I did not mention 3rd dimension, because this part is trivial.

Openscad is not a nice programming language to me. As a design tool, it appears clumsy to me, but I can understand why someone would use it.

As I stated I don't know DesignSpark M.I know Freecad a bit and I don't like the GUI. But I would never recommend anyone not to check it out. It is a nice piece of free software.Freecad is not convenient to me, but I recognize it's very powerful.

Ok that code was horrible but I hope it gets the point across. You do the loop in Java which generates a file that tells OpenSCAD exactly what you want using procedural statements and constants, rather than trying to do loops and calculations and whatever else in OpenSCAD.

nitewatchman wrote:it was much cleaner and easier than killing a chicken on top of the printer.

Ok that code was horrible but I hope it gets the point across. You do the loop in Java which generates a file that tells OpenSCAD exactly what you want using procedural statements and constants, rather than trying to do loops and calculations and whatever else in OpenSCAD.

Thanks for the workaround.

Actually, the wall was just an exercice... it's not like I need it. But I'm glad I tried it right in the beginning, so that I could realize that openscad is just not for me.

Using any programming language, I'm sure there are ways to do the same in a more elegant and practical way by directly buiding a stl file or similar, rather than writing openscad commands.