Creating button using sketchup Ruby

At first, your code above is hardly readable, so I would like to ask you to properly post the code:
[How to] Post correctly formatted and colorized code on the forum? - Developers - SketchUp Community



Secondly: You can start to learn starting from e.g. here:
Welcome! | SketchUp Developer
…and many other resources collected by Dan:
Ruby Learning Resources [WikiLists] - Developers / Ruby API - SketchUp Community



Now, about your question very briefly. Be aware that you need to properly namespace your code if you want to publish it… more you can read the links above… :wink:

The " action/command" you are looking for called method, which you have to define:

def my_first_method()
  model = Sketchup.active_model
  sel = model.selection[0]
  tr = Geom::Transformation.translation([50,0,0])

  sel.transform!(tr)
end

Then you can create a command object to call this method.

.
.
  cmd1 = UI::Command.new(" Bouton 1") {
    my_first_method()
  }
.
.
2 Likes