[Tutorial] Beginning Ruby 2 - Writing a Script
-
All right, I finally put together a second tutorial on script writing in Ruby. It is located here (the advanced tutorial section of the main sketchucation site):
http://www.sketchucation.com/beginning-ruby-2-writing-a-script/
The first one is here.
Anyhow, look it over. Its a pretty baic script that iterates through a model, finds all the faces, then pushpulls them to a specified distance. It shows how to use the undo stack, safety wrap a scipt inside a module, use the inputbox, and add the script to the menu system.
One of the coolest things about the tutorial is Coen's new Ruby feature in the tutorials section. So instead of screenshots of ruby, it actually has ruby code that you can copy and paste.
Chris
-
Thanks Chris, this is great - who knows one day even i..
-
Nice one Chris.
I'd like to point out some inconsistency though.
Some places you use
.typename
and some places you use.is_a?
.Interesting findings from this post, http://forums.sketchucation.com/viewtopic.php?f=180&t=19576&start=0#p162235 , shows that
.typename
is very slow. Best practice would be to use.is_a?
or.kind_of?
(they are aliases of the same method.) Or compare the.class
. -
Oops, I should fix that. Its a remnant of the old script where I used .typename regularly. I guess I forgot to update it in some places. I know the first tutorial still uses .typename because I did not get a chance to update that one. I'm planning on redoing the entire tutorial.
So I'll look them both over for inconstiencies again. I also want to add more links back to the API in the 2nd one. There are a few methods I refer to but don't link back to them.
Thanks Thom!
Chris
-
I wonder if we should make a sticky thread that list some of these 'tricks' / 'best practices' that's scattered throughout the forum... ?
-
Are the rubie scripts based in the old dBase manner. It's been years for me but it looks almost the same as I remember...
Advertisement