# How to group groups

**URL:** <https://forums.sketchup.com/t/how-to-group-groups/120054>\
**Category:** Ruby API\
**Created:** [March 27, 2020, 5:08pm UTC](https://forums.sketchup.com/t/how-to-group-groups/120054 "2020-03-27T17:08:49Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 27, 2020, 6:46pm UTC](https://forums.sketchup.com/t/how-to-group-groups/120054/2 "2020-03-27T18:46:24Z")

</div>

Reassigned this topic thread to the **Ruby API** subcategory.

* * *

**FYI** , Please read how to post color lexed code in the forum …

- [[How to] Post correctly formatted and colorized code on the forum?](https://forums.sketchup.com/t/how-to-colourize-code-on-the-forum-wiki/46189)

* * *

> [@Aviad](#):
>
> I can use the documentations but for a beginner, it’s a bit difficult.

As said many times here in other threads, the API documentation is a programmer’s reference.  
It is not a teaching resource, and it’s code snippets range from worthless to erroneous.

> [@Aviad](#):
>
> there is any good tutorial or book for this specific purpose?

See the wiki lists of resources for learning Ruby and then how the SketchUp API extends the Ruby core…

> [@Ruby Learning Resources \[WikiLists\]](https://forums.sketchup.com/t/ruby-learning-resources-wikilists/22861/):
>
> All seven of the lists below are set as wikis. card_index INDEX [notebook PRIMERS & GUIDES](http://forums.sketchup.com/t/ruby-learning-resources/22861/2)[books BOOKS](http://forums.sketchup.com/t/ruby-learning-resources/22861/3)[mortar_board TUTORIALS](http://forums.sketchup.com/t/ruby-learning-resources/22861/4)[card_box REFERENCE](http://forums.sketchup.com/t/ruby-learning-resources/22861/5)[clipboard TEMPLATES](http://forums.sketchup.com/t/ruby-learning-resources/22861/6)[newspaper NEWS](http://forums.sketchup.com/t/ruby-learning-resources/22861/7)[bulb IDEAS](http://forums.sketchup.com/t/ruby-learning-resources/22861/8)

In addition … ALL of your code, for ANY of your extensions, must be within a company or author namespace module. Then each of your extensions should be in a separate submodule within your namespace module.

I long ago posted a simple template for Basic extensions …

- [[Template] for Basic SketchUp Extension](https://forums.sketchup.com/t/template-for-basic-sketchup-extension/24658)

* * *

> [@Aviad](#):
>
> ```ruby
> SKETCHUP_CONSOLE.show
> 
> ```

This would need to be removed after development, or you could make it dependent upon a debug / dev flag variable in your module.

But it is probably easier to use a console opener extension.

> **[SketchUp Extension Warehouse](https://extensions.sketchup.com/extension/461ee6e6-1387-45dc-a071-8f136ad2376b/eneroth-console-opener)**
>
> Your library of custom third-party extensions created to optimize your SketchUp workflow.

> [@Aviad](#):
>
> ```ruby
> require 'sketchup.rb'
> 
> ```

You do not need to require **other files** in your file, **unless** your file uses features defined in that **other file**.

In this case … SketchUp itself will **already have** loaded all 3 of the “special” files in it’s **Tools** subfolder (ie, `"sketchup.rb"`, `"langhandler.rb"`, and `"extensions.rb"`,) before any custom extension (including yours) has even begun to load.

* * *

Proper SketchUp extensions require a extension subfolder and a registrar script of the same name in the “Plugins” directory folder. _See:_

- class [`SketchupExtension`](https://ruby.sketchup.com/SketchupExtension.html)

* * *

Looking at your code quickly …

`1`. Ruby uses **2** space indentation. Some of your indents are **3** spaces.

`2`. `"Plugin"` is misspelled `"Pluing"`

`3`. `"Stairs"` is misspelled `"Staris"`

`4`. `"Staircase"` is misspelled `"Staricase"`

`5`. Use the **active** entities and you never know at what level the user will want to create their stairs:

```ruby
   ents = mod.active_entities

```

`6`. The “ **Lets Start!** ” messagebox is frivolous and the input dialog does a good job **on it’s own** of signalling the beginning of the command cycle. (Both of them are modal dialogs that force the user to deal with them, so just use the input dialog.)

`7`. Your menu item proc should only call a command method. This way you can tweak your method code, reload your main file, and it will redefine the command method. Your way, you have to exit SketchUp and restart the application just to see the new functionality.

Example …

```ruby
    def create_staircase_command
      prompts = ["Number of Stairs"]
      defaults = ["1"]
      input = UI.inputbox(prompts, defaults, "Staircase Creator")
      # Always check if user cancelled:
      return unless input # evals falsely if user cancels inpubox
      # User did not cancel and input is an array, so draw the stairs:
      draw_stairs(input)
    end

```

… and down at the bottom of your module …

```ruby
    unless @loaded
      UI.menu("Extensions").add_item("Create Staircase...") {
        create_staircase_command()
      }
      @loaded = true
    end

```

Notice how the creation of UI menu items (commands, toolbars and buttons) must be done within a conditional that only happens upon first load. This prevents duplicate menu items when you reload files during development (which you’ll be doing many times.)

* * *

`8`. You do not need to write your own unit conversion methods. The SketchUp API added many conversion methods to the `Numeric` class, which passes them on down to `Integer`, `Float`, etc.  
_See:_

- [SketchUp API **`Numeric`** class method additions](https://ruby.sketchup.com/Numeric.html)
- [SketchUp API `Length` class](https://ruby.sketchup.com/Length.html)
- [Ruby Core `Numeric` class](https://ruby-doc.org/core-2.5.5/Numeric.html)
- [Ruby Core `Integer` class](https://ruby-doc.org/core-2.5.5/Integer.html)
- [Ruby Core `Float` class](https://ruby-doc.org/core-2.5.5/Float.html)

In addition, the `UI.inpubox` will correctly convert between model units and internal `Length` (inches).  
This means you do not need to write your code specifically for metric or imperial units. Read ThomThom’s primer blog on dealing with units and inputboxes …

[http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/](http://www.thomthom.net/thoughts/2012/08/dealing-with-units-in-sketchup/)

Oh … and my last thought is you’ll need to move `rise`, `run` and `tread width` into the inputbox so users can tailor the staircase to their own needs (and local building codes.)

---

_[View the full topic](https://forums.sketchup.com/t/how-to-group-groups/120054)._
