# Create custom tool

**URL:** <https://forums.sketchup.com/t/create-custom-tool/33212>\
**Category:** Ruby API\
**Created:** [November 4, 2016, 12:53pm UTC](https://forums.sketchup.com/t/create-custom-tool/33212 "2016-11-04T12:53:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamjankowski](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@mamjankowski](https://forums.sketchup.com/u/mamjankowski)\
**Post date:** [November 4, 2016, 12:53pm UTC](https://forums.sketchup.com/t/create-custom-tool/33212/1 "2016-11-04T12:53:14Z")

</div>

I need to make my own tool, very similar to “Line” but a little bit extended.  
First of all I need to draw line (using my new tool) always in the same Z level.  
After draw a line I need to draw rectangle (length = length of line, width and height = choose by user). And make some other things. This I can make in observer.  
My plan is:

1. choose tool which starts observer (Sketchup::EntitiesObserver def onElementAdded)
2. draw a line
3. draw a rectangle and push face
4. make DC
5. stops observer after change tool to another

But I don’t have idea how to make a tool which starts observer and after change tool to another, stops observer.

---

<div class="post-metadata">

**Author:** ![Wo3Dan](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/wo3dan/32/7450_2.png) [@Wo3Dan](https://forums.sketchup.com/u/Wo3Dan)\
**Post date:** [November 4, 2016, 3:10pm UTC](https://forums.sketchup.com/t/create-custom-tool/33212/2 "2016-11-04T15:10:47Z")

</div>

What is your end goal with this tool?

---

<div class="post-metadata">

**Author:** ![mamjankowski](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@mamjankowski](https://forums.sketchup.com/u/mamjankowski)\
**Post date:** [November 4, 2016, 3:28pm UTC](https://forums.sketchup.com/t/create-custom-tool/33212/3 "2016-11-04T15:28:11Z")

</div>

I have to make plinths under kitchen cupboards. I would like to draw a few edges and base on them make plinths as Dynamic Components. It should be maximally easy to use for end-users.

---

<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:** [November 4, 2016, 8:46pm UTC](https://forums.sketchup.com/t/create-custom-tool/33212/4 "2016-11-04T20:46:20Z")

</div>

RE, the line tool, you can start with the example line tool ("`linetool.rb"`) in the “[Example Ruby Scripts](http://extensions.sketchup.com/en/content/example-ruby-scripts)” extension, by the SketchUp Team.

- [Extension | SketchUp Extension Warehouse](http://extensions.sketchup.com/en/content/example-ruby-scripts)

> [@mamjankowski](#):
>
> But I don’t have idea how to make a tool which **starts observer** and after change tool to another, stops observer.

I just posted an example in this category day before last:

- [How can I get the event when material dropped on Face](http://forums.sketchup.com/t/how-can-i-get-the-event-when-material-dropped-on-face/33032/5)

* * *

**But** , … it would be best not to actually create temporary edges and faces, but instead just write a 3 click tool that draws a virtual 3D box on the screen, and then **after** the 3rd click it creates the dynamic component.

This way, you will not need the observer kludge.

---

<div class="post-metadata">

**Author:** ![mamjankowski](https://avatars.discourse-cdn.com/v4/letter/m/c37758/32.png) [@mamjankowski](https://forums.sketchup.com/u/mamjankowski)\
**Post date:** [November 5, 2016, 7:39am UTC](https://forums.sketchup.com/t/create-custom-tool/33212/5 "2016-11-05T07:39:39Z")

</div>

Dan, what do you mean virtual 3d box?  
In my case plinth goes ones streight, turn left, next turn right, etc. And I need each piece to be separatly DC.

---

<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:** [November 5, 2016, 6:29pm UTC](https://forums.sketchup.com/t/create-custom-tool/33212/6 "2016-11-05T18:29:42Z")

</div>

> [@mamjankowski](#):
>
> Dan, what do you mean virtual 3d box?

In SketchUp, activate the native RectangleTool.  
Click somewhere once.  
Move the mouse cursor,…

… do you see the tool drawing a virtual 2D rectangle onto the viewport ?

This is done (in your tools) using the various instance methods (beginning with the word “draw”,) of the [**`Sketchup::View`**](http://ruby.sketchup.com/Sketchup/View.html#draw-instance_method) class. These methods only work within the [**`draw()`**](http://ruby.sketchup.com/Sketchup/Tool.html#draw-instance_method) callback method of your [**`Tool`**](http://ruby.sketchup.com/Sketchup/Tool.html) class.

* * *

So your cubic or volumetric tool should be drawing a rectangle between the first and second clicks, and then a volume between the second and third clicks.

After the third click, you then (and only then,) actually create model geometry (within an [undo operation](http://ruby.sketchup.com/Sketchup/Model.html#start_operation-instance_method) block.)

If the user clicks the ESC key at any time before the third click, your tool should reset to it’s initial state.
