Beginning Ruby Tutorial
-
That is not in the turorial, but it will be in a future one I hope. The idea there is implementing a tool class in your script. I can write up a quick start template, but I can't get too in depth right now. Hopefully alter in a tutorial though.
Chris
PS I think the tutorials are open to anyone to write at this point. If aynone out there wants to do a better on, or do one on a different topic, they are more than welcome to go for it! I think we might need a new tutorial template though for Ruby tutorials. The current one is very little text and very much image - not ideal for Ruby. Maybe I'll outline what I think a Ruby tutorials might need, and then see if Coen has time to implement it eventually.
-
Neat presentation!
-
Yeah! An Ruby introduction for Sketchup fans .
Thanks a lot Chris, for listening poor newbies !
MALAISE
-
thanks Chris. that's really great. hopefully I will have time soon to check it out. such a tutorial was dearly deeded for noobs like me to get started
-
Great work Chris, that kind of tutorial was really needed.
@unknownuser said:
Small typo, second paragragh thats all
James,you are slacking.
-
Looks very good. This might tip me finally to start doing something about it.
-
Hi Chris
Is-it possible to resize the Web console "window"? We hardly read the contain ( too small font)
Thanks
MALAISE
-
Thanks Chris
I have really always wanted to give it a try, or at least understand Rubys in greater depth.
Thanks for the effort. -
Thanks for the great comments, I hope it gets more people interested in beginning. I'm sure there are other roads to take to get into Ruby, but thats how I did it, so its the only way I can explain. Hopefully it will be logical enough for others to use too.
Malaise, sorry the font is small. If you click on most of the images, it shows a full size image. But if the full size image is too small also...hmm. I don't know. I bet I could also provide a link to the .rb script for download right up front, for people who can't read the images very well.
But if I provide the link to the text script, its not a free pass to just copy and paste
Chris
-
@BTM (and anyone interested) I did go ahead and write up a quick tool script that creates a tool, which is how you get the onmousemove and all other tool methods to work. Check it out here:
http://www.sketchucation.com/forums/scf/viewtopic.php?f=180&t=18801
-
Chris,
Thanks for making a ruby tutorial.
Its always inspiring to look at someone else's code.
Here is a version which use a hash instead of arrays to count all entities types;
def count_entities model = Sketchup.active_model entities = model.entities count = {} # start a new hash entities.each do |e| stype = e.typename # start new count, or add 1 to existing count count[stype] = count[stype] ? count[stype] + 1 ; 1 end#loop sorted_keys = count.keys.sort sorted_keys.each do |key| printf("Total %-12s; %5d\n", key, count[key]) end#loop return nil end#def
The weird line:
count[stype] = count[stype] ? count[stype] + 1 : 1
would be easier to read as
if (count[stype]) count[stype] = count[stype] + 1 else count[stype] = 1 end#if
Keep up the good work
Advertisement