LineTool example

What’s up with this ruby example -I run it and it does not do anything -is it out of date?

All the ruby examples seem old and there seems to be undocumented methods in them.
The linetool.rb seems to execute OK but if I try to select linetool it gives me the pencil

Anyone have a simple example of using mouse input to position an object?

This is the expected behavior. The line tool is represented by a pencil icon in SketchUp. You may possibly be thinking of the line tool behavior in AutoCAD or a related cad software.

To position a line object in SU, simply click on a point to start the line, drag the cursor to where you want the line to end, then release.

Yes they are old. They have changed very little over the years. But they still work.

Assuming that means with regard to the API documentation, this is fine because they are custom internal methods that are unique to the author and these custom classes. Most custom Ruby classes and modules will have unique internal methods. (Internal methods are those only called by other methods of the class or module. They do not get called by any other external Ruby object. Since they are not SketchUp API methods, they will not appear in the SketchUp API documentation.)

IMO, all of the methods are commented quite well.

These files are not tutorials. They do not teach Ruby. They are examples meant for programmers who know Ruby, and need specific examples of how to use specific SketchUp API features with Ruby.

The SketchUp Ruby API allows only creating custom tools.

Native SketchUp tools are not written in Ruby, and so cannot be overridden by Ruby. (And even if this could happen, it would not be allowed. It would create a nightmare for SketchUp Customer Support.)

In the file (just above the defintion of class LineTool,) it states:

“This tool is similar to the Pencil tool in SketchUp, but it create construction lines rather than edges

It is not supposed to do anything, until one of it’s classes is instantiated and used to become the active tool.

The API’s abstract Tool class, is an event-driven code object. Once, active, it sits there and responds based upon what the user does with the mouse, or keyboard.

At the bottom of the file, two module functions are defined to active each of the two tool examples.
So, at the console, type:
… and the example will be activated.

Oh I see, thanks jvleearchitects
I thought it was supposed to give me a tool that draws a guide line so I expected it to look like a guideline.

As near as I can tell they come from SketchUp.rb -I assume it is some sort of system file?

Sorry DanRathbun, trying to learn Ruby is frustrating. I have only been at it a week and am still green. I had assumed they where there to teach people how to use Ruby to make SketchUp do stuff. I was using the wrong syntax to try and activate it

They may be commented well for an experienced programmer but for newb’s they make many assumptions. -but I guess they are not meant to teach either.

If I had read all the way through Automatic Sketchup before trying to make a script I would have learned that but I am not always as patient as i need to be.

Here is an example of the method descriptions lacking information

puts "Point 0: " + pent.vertices[0].position.to_s

I lookup vertices and it says nothing about position and lookup position and it says nothing about to_s

Are there so many methods that can act on any particular method that they can’t be listed?

Here is the example for the vertices method:

depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]

Add the face to the entities in the model

face = entities.add_face(pts)
vertices = face.vertices

saying: vertices = face.vertices is not all that helpful

face.vertices actually returns
[Sketchup::Vertex:0x0000000a0ee020, Sketchup::Vertex:0x0000000a0edff8, Sketchup::Vertex:0x0000000a0edfd0, Sketchup::Vertex:0x0000000a0edfa8]

which would at least demonstrate what it is actually doing without having to copy and paste it into the console

.GetString -and that is documented where?

I look through the “linetool.rb” example, but I cannot find this statement.

(If you are changing the subject, please begin a new topic.)

That certainly clears up a lot - thanks

Indeed, “sketchup.rb” is a script that (since SketchUp 2014,) gets loaded before any plugins or extensions get loaded. So the act of requiring it (since) is frivolous.

But this issue is discussed in another topic:
To require “sketchup.rb”, or not to … that is the question

In this specific case of “linetool.rb”, there appears to not be any use of the global methods defined in “sketchup.rb”, so the author may be using the require statement as a marker statement as Aerilius suggests (in the topic listed above.)

The “sketchup.rb” file is located in the “Tools” sub-directory of the SketchUp program directory. (… despite what it says at the top of the “su_examples.rb” and “examplescripts.rb” files.)

The “linetool.rb” file’s loading, is ultimately caused by the “su_examples.rb” extension registration script, in the “Plugins” directory, (which loads “examplescripts.rb”, which loads all the example scripts, in the “su_examples” extension sub-directory.)

In the “su_examples.rb” you’ll see the loading of “sketchup.rb”, “extensions.rb” and “langhandler.rb”. All 3 are located in the “Tools” sub-directory of the SketchUp program directory.

The functionality of “sketchup.rb” remains undocumented. (But this has been discussed ad nauseum elsewhere, and is a bit off-topic.)

The “extensions.rb” file defines the SketchupExtension class, which is documented.

The “langhandler.rb” file defines the LanguageHandler class, which has always had the .GetString method, but in response to a request by myself, (for SU2014+) they renamed it [] (square brackets) and aliased it as GetString. (To have extensions that still work with older versions, you’d need to use the old name. That is why they have not changed it.)
Some thing is wrong with the documentation generator as it is not listing the method aliases.

I personally use the square bracket method myself, and create singleton methods if a method response test is negative:

    @strings ="my_plugin.strings")
    if !@strings.respond_to?(:[])
      def @strings.[](arg)

The GetString name is not Rubyish, and shows the original author’s Java or Javascript roots. The square bracket accessor is the way it is done in Ruby for Hash-like objects, from which data is accessed by a key.

Where is your code to get the position of mouse with linetool. I want to read that but found nothing in this page

It was not his code. This thread discusses the "linetool.rb" example from the SketchUp Team set of Examples.

Get the example scripts at the Extension Warehouse:

I am reading it. I tried to change it to read 3 points, but not succeed yet.