by cjbissonnette, published
To get the latest code please either download from github or better yet use the rubygem.
RubyGem (thanks knewter):
Use the full power of ruby / rubygems to create more powerful objects. Classes can be made that are subclassed to add functionality, mixin modules can be made to expand the language, and command line arguments can be used to make scripts customizable from the command line. I think having a full OOD language can make for some interesting objects.
-Use ruby syntax to create compatible openscad scripts...done
-Include all the functionality of openscad...done except dxf_dim and dxf_cross (if somebody knows how to extract these pieces of information using ruby please let me know)
-be able to continue to use existing openscad libraries/ arbitrary existing openscad code...done
-lightweight...done (~300 lines, 1 file)
-match openscad syntax as much as possible for easy transition... done (very few exceptions, see instructions)
Recent Commentsview all
Cool! All the features I listed are already operational. Make sure you have ruby 2.0 installed and gem install oozby to have a play with it. There's a little 'oozby' command line app which you run as 'oozby compile some_directory' and it'll watch for file changes and make corrosponding .scad files from .oozby files in there, and report any errors in that terminal window. Lots of demos in the examples folder on github to play with. I'm working on making some pretty documentation which will hopefully be online in the next few weeks :)
I am definitely going to check this out. When I first started this project it was my intent to add a lot of the improvements that you are referring to. I added some small things like being able to supply diameter as a parameter to cylinders and circles, but never found the time to add more features. I'm excited you are taking this idea further, I think being able to harness the power of ruby would push openscad's usefulness greatly.
I've been recently working on a more in depth version of this idea called Oozby. http://creativepony.com/oozby/ little homepage, and on github at http://github.com/bluebie/oozb... - More than just using ruby grammar, my goal with oozby is to use ruby as a preprocessor to add more features like rounded cubes, squares, cylinders (like border-radius in css!), be able to make classes which generate objects, have the language detect bugs and give you much more useful error messages than OpenSCAD, and have it much more tollerant of typos and try to understand programmer's intent, so you don't need to keep a reference open at all times to look up exact argument names. Everything that takes a height can take it as h: or height: and everything which takes a radius can take it as radius: or r: or you can specify it as diameter: or d: and have it automatically halved. You can specify radius/diameter as a Range to cylinder instead of r1 and r2 if you like, or create a scope where everything inside defaults to center: true instead of center: false. Lots of neat stuff. If you play with it at all I'd love some feedback ^_^
Oozby is very much a work in progress but I'm using it for modelling almost every day now and so I'm personally pretty invested in not breaking my own code. I think stuff built on oozby today will almost certainly work fine in future versions. :)
Liked Byview all
Give a Shout Out
I added a quick language def which outlines all the functions, and a new example "knob.rb" which is another example to use.
I have converted the 22 examples included with openscad into RubyScad scripts. These use just about every command in the openscad language and will detail the syntax. I will highlight some of the features below / some of the common pitfalls when migrating.
Install Ruby 1.9.3 > (in ubuntu repos, easy windows and mac auto install): ruby-lang.org/en/
Install RubyGems: rubygems.org/
Run: gem install rubyscad
in a blank ruby document i.e. test.rb:
then simple run this from command line:
this will print the output to the command line which can be piped to a file OR
run the file with a string as the first argument::
ruby test.rb "output.scad"
which will create "output.scad" file in the same directory
Using A Module
sphere(r: 3, center:true)
Using A Class
@size = args.fetch(:size, 1)
To use an existing library:
format_command "writecylinder(%s);", args
writecylinder(text: "test", where: [0,0,0])
To output any string directly to openscad use:
-When using a function it is general named the same as the openscad function i.e. cube, sphere... with the exception of the include function which is "scad_include" so as not to interfere with rubyâ€™s function of the same name
-Functions always accept a hash for their arguments so all calls will look like: cube(size: 6, center:true) which means the following is ILLEGAL: translate([1,2,3]) and must be converted to translate(v:[1,2,3] or optionally translate(x:1,y:2,z:3). Exceptions to this are "echo" which takes any number of arguments, and create an echo statement in openscad i.e. echo 4, 5, "test". "use", and "scad_include" take one string i.e. use "write.scad".
-To set global '$' variables use the associated function "$fa = 4" becomes "fa 4", "$fs = 6" becomes "fs 6", and "$fn = 12" becomes "fn 12"
Thatâ€™s the high level overview, look at the examples for more details, or leave a comment if I need to clarify something.
You must be logged in to post a comment.