Create custom tool

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.

What is your end goal with this tool?

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.

RE, the line tool, you can start with the example line tool ("linetool.rb") in the “Example Ruby Scripts” extension, by the SketchUp Team.

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

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.

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.

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 class. These methods only work within the draw() callback method of your Tool 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 block.)

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