# How to add button and lineedit in UI with ruby

**URL:** <https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848>\
**Category:** Ruby API\
**Tags:** sketchup\
**Created:** [August 28, 2019, 4:42am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848 "2019-08-28T04:42:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ltc1996](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@ltc1996](https://forums.sketchup.com/u/ltc1996)\
**Post date:** [August 28, 2019, 4:42am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/1 "2019-08-28T04:42:57Z")

</div>

Hey guys, i want to design UI for my ruby plugin and i need a button for user to choose folder. The whole UI is like this:

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/4/c/4c398f9b487f2d48bbdbe1ca2c2baf02384ffc2c.png)  
After i click the button, `UI.select_directory` pops up, and fill the lineedit with path. But i dont know how to connect the button in the interface.

---

<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:** [August 28, 2019, 5:24am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/2 "2019-08-28T05:24:05Z")

</div>

You will need to use **[`UI::HtmlDialog`](http://ruby.sketchup.com/UI/HtmlDialog.html)** class.

In the HTML web page for the interface identify the path edit control with an ID (`"path_edit_ID"` for this example.)

```nohighlight
<input type="button" value="Choose folder" onclick="getPath;"/>

```

Then add an onClick JS function for the button …  
In JS …

```nohighlight
<script=javascript>
function getPath () {
    sketchup.browse_for_path
}
</script>

```

… that makes a Ruby callback whose block makes the call to `UI.select_directory()`.  
In Ruby …

```ruby
@dialog.add_action_callback("browse_for_path") { | action_context |
  path = UI.select_directory(
    title: "Select Image Directory",
    directory: "C:/images"
  )
  send_path_to_dialog(path) if path
}

```

If the return value from the call is a valid string (boolean `true` in Ruby) then make a call to the dialog sending over the path string to the path edit box by ID.

```ruby
def send_path_to_dialog(path)
  @dialog.execute_script("path_edit_ID.value='#{path}';")
end

```

… or …

```ruby
def send_path_to_dialog(path)
  @dialog.execute_script("document.getElementByID('path_edit_ID').value='#{path}';")
end

```

(Can’t remember if the former will work.)

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [August 28, 2019, 10:05am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/3 "2019-08-28T10:05:59Z")

</div>

We have some HtmlDialog example on GitHub you can look at for reference:

> **[GitHub - SketchUp/htmldialog-examples: Examples of using SketchUp Ruby API's...](https://github.com/SketchUp/htmldialog-examples)**
>
> Examples of using SketchUp Ruby API's UI::HtmlDialog class - GitHub - SketchUp/htmldialog-examples: Examples of using SketchUp Ruby API's UI::HtmlDialog class

> **[GitHub - SketchUp/htmldialog-inputbox: UI::HtmlDialog example recreating...](https://github.com/SketchUp/htmldialog-inputbox)**
>
> UI::HtmlDialog example recreating UI.inputbox functionality in the SketchUp Ruby API - GitHub - SketchUp/htmldialog-inputbox: UI::HtmlDialog example recreating UI.inputbox functionality in the Sket...

---

<div class="post-metadata">

**Author:** ![ltc1996](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@ltc1996](https://forums.sketchup.com/u/ltc1996)\
**Post date:** [August 28, 2019, 10:24am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/4 "2019-08-28T10:24:08Z")

</div>

This is so cool, can i find API of `HtmlUI` ?😀

---

<div class="post-metadata">

**Author:** ![ltc1996](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@ltc1996](https://forums.sketchup.com/u/ltc1996)\
**Post date:** [August 28, 2019, 10:25am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/5 "2019-08-28T10:25:42Z")

</div>

This works~ now i can write the core code of my plugin.😉

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [August 28, 2019, 12:23pm UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/6 "2019-08-28T12:23:31Z")

</div>

> [@ltc1996](#):
>
> This is so cool, can i find API of `HtmlUI` ?😀

The SketchUp Ruby API is documented here: [http://ruby.sketchup.com/](http://ruby.sketchup.com/)

In addition to that key resources are:

- [https://developer.sketchup.com/en](https://developer.sketchup.com/en)
- [SketchUp · GitHub](https://github.com/SketchUp)

---

<div class="post-metadata">

**Author:** ![ltc1996](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@ltc1996](https://forums.sketchup.com/u/ltc1996)\
**Post date:** [August 29, 2019, 6:55am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/7 "2019-08-29T06:55:13Z")

</div>

This really helps a lot.  
I have a question about Ruby API: after i install Thea for SketchUp, can i get it in my `Ruby` plugin to ‘Click’ the final submenu ‘Export Model as Thea Scene’.  
Could I get the extension API to ‘Click’ the desired submenu?  
Maybe it’s like simulate the mouse click, maybe not. I don’t know if i can implement via `.rb`.🧐

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/4/e/4e86a9f32a80cf9b4d972a701e104d0a76f6c14d.png)

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [August 29, 2019, 8:59am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/8 "2019-08-29T08:59:39Z")

</div>

No way to drive menu clicks from the Ruby API. Instead you’d invoke the ruby methods the menu would invoke. When it’s not your own extension you try to invoke you can try to reach out to the developer and ask for details.

---

<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:** [August 29, 2019, 2:18pm UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/9 "2019-08-29T14:18:42Z")

</div>

The easiest thing to do (if the Thea extension does not expose commands to other coders,) is to assign a shortcut keychord to the export menu item, and then use `WIN32OLE` and the `SendKeys` method call. (But this only MS Windows.)

See my response to your other post …  
[Use the ruby code to simulate a mouse click on the sub-menu in menu - #5 by DanRathbun](https://forums.sketchup.com/t/use-the-ruby-code-to-simulate-a-mouse-click-on-the-sub-menu-in-menu/71348/5)

---

<div class="post-metadata">

**Author:** ![ltc1996](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@ltc1996](https://forums.sketchup.com/u/ltc1996)\
**Post date:** [September 2, 2019, 2:55am UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/10 "2019-09-02T02:55:54Z")

</div>

Wow, i can’t believe you can see that. After i posted that when i realized that it was posted ONE YEAR AGO in the first place! Thans you very much for your wonderful answer.😀

---

<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:** [September 2, 2019, 2:58pm UTC](https://forums.sketchup.com/t/how-to-add-button-and-lineedit-in-ui-with-ruby/101848/11 "2019-09-02T14:58:05Z")

</div>

> [@ltc1996](#):
>
> Wow, i can’t believe you can see that. After i posted that when i realized that it was posted ONE YEAR AGO in the first place!

Well your post revived the topic and brought it to the top of the [Latest](https://forums.sketchup.com/latest) list, so everyone will “see” that the thread had “traffic”.

Glad ya’ liked the answer.
