sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Beginning Ruby Tutorial

    Scheduled Pinned Locked Moved Developers' Forum
    16 Posts 11 Posters 728 Views 11 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      ok, so I've just finished up my first attempt at a beginners tutorial on how to get setup and ready to write Ruby scripts, and it also explains how to write a basic code to find and sort entities in a model (not all entiites, just edges, faces, compInstances, and groups).

      Anyhow, I think its a great place to start for beginners. And I was maybe also hoping that someone who knows more about the technical aspects of Ruby could take a look at it and spot check for any glaring errors. My technical expertise with Ruby is, shall we say, in need of improvement 😄

      But I think its a good start of a tutorial. And I've got a few more ideas planned for some more basic Ruby How To's in the future. But I'd like to get this one reviewed and updated before I get going on anything more. Here's the link,

      Link Preview Image
      SketchUcation

      3D SketchUp Community for Design and Engineering Professionals.

      favicon

      (www.sketchucation.com)

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • R Offline
        remus
        last edited by

        Thats a very nice little tutorial, thanks 👍

        http://remusrendering.wordpress.com/

        1 Reply Last reply Reply Quote 0
        • kenK Offline
          ken
          last edited by

          Thanks Chris. I wanted to get started and this appears as something I can do.

          Just a note, seems to me you must have 30 hours in your day.

          Thanks

          Ken

          Fight like your the third monkey on Noah's Ark gangway.

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            Thanks folks! Hopefully its straightforward enough that anyone can use it as guide to getting started. I don't have the ability to actually teach the Ruby language, but there are other tutorials for that, and you'll need to invest some time (for me, I spent about 2 days just doing plain Ruby tutorials before I started to look at SketchUp Ruby). So, there is a Ruby learning Curve, but if you can put some time in to get acquinated with Ruby, this should help fill the gap of how to get started on Ruby for SketchUp.

            And a HUGE thanks To Gaieus, James, and Coen for helping me get started, keep going, start over, restart, stop, erase and delete, and finally restart and finish this tutorial 😄 They were my grief and guidance counselors.

            Ok, typo fixed James, thanks for that one!

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • B Offline
              BTM
              last edited by

              ... I might have a look later, not enough time to look through the whole thing right now though 😆 .

              Also, I've been trying to figure out how to implement mouse control in ruby script; I think Chris Phillips might know a thing or two (considering how much mouse interaction there is in sketchyphysics), but if there's anyone else out there that could help out at explaining what do do, that would be great.

              So far, all I know is that it would involve def onMouseMove(flags, x, y, view) (view is model, which is Sketchup.active_model, .active_view), aswell as def onLButtonDown(flags, x, y, view), def onLButtonUp(flags, x, y, view) and def draw(view). Or at least I THINK those are what I need to use.

              Anyways, if anyone knows how, I would really appreciate it if you could explain a bit, or if it's in the tutorial (which I haven't been able to look at yet), that would work too 😆

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                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.

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • pilouP Offline
                  pilou
                  last edited by

                  Neat presentation! 😎

                  Frenchy Pilou
                  Is beautiful that please without concept!
                  My Little site :)

                  1 Reply Last reply Reply Quote 0
                  • MALAISEM Offline
                    MALAISE
                    last edited by

                    Yeah! An Ruby introduction for Sketchup fans .

                    Thanks a lot Chris, for listening poor newbies ! 😆

                    MALAISE

                    La Connaissance n'a de valeur que partagée

                    1 Reply Last reply Reply Quote 0
                    • plot-parisP Offline
                      plot-paris
                      last edited by

                      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 👍

                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        mateo soletic
                        last edited by

                        Great work Chris, that kind of tutorial was really needed. 👍

                        @unknownuser said:

                        Small typo, second paragragh thats all

                        James,you are slacking. 😆

                        [Concept Illustrations](http://concept-illustrations.com/)

                        1 Reply Last reply Reply Quote 0
                        • S Offline
                          sepo
                          last edited by

                          Looks very good. This might tip me finally to start doing something about it. 👍

                          1 Reply Last reply Reply Quote 0
                          • MALAISEM Offline
                            MALAISE
                            last edited by

                            Hi Chris

                            Is-it possible to resize the Web console "window"? We hardly read the contain ( too small font)

                            Thanks

                            MALAISE

                            La Connaissance n'a de valeur que partagée

                            1 Reply Last reply Reply Quote 0
                            • daleD Offline
                              dale
                              last edited by

                              Thanks Chris
                              I have really always wanted to give it a try, or at least understand Rubys in greater depth.
                              Thanks for the effort.

                              Just monkeying around....like Monsanto

                              1 Reply Last reply Reply Quote 0
                              • Chris FullmerC Offline
                                Chris Fullmer
                                last edited by

                                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

                                Lately you've been tan, suspicious for the winter.
                                All my Plugins I've written

                                1 Reply Last reply Reply Quote 0
                                • Chris FullmerC Offline
                                  Chris Fullmer
                                  last edited by

                                  @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:

                                  301 Moved Permanently

                                  favicon

                                  (www.sketchucation.com)

                                  Lately you've been tan, suspicious for the winter.
                                  All my Plugins I've written

                                  1 Reply Last reply Reply Quote 0
                                  • Al HartA Offline
                                    Al Hart
                                    last edited by

                                    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

                                    Al Hart

                                    http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                                    IRender nXt from Render Plus

                                    1 Reply Last reply Reply Quote 0
                                    • 1 / 1
                                    • First post
                                      Last post
                                    Buy SketchPlus
                                    Buy SUbD
                                    Buy WrapR
                                    Buy eBook
                                    Buy Modelur
                                    Buy Vertex Tools
                                    Buy SketchCuisine
                                    Buy FormFonts

                                    Advertisement