Ruby API Documentation - Errors & Suggestions

in the Sketchup Selection class

in the Selection.remove() method, it says selection.add() in the example box. Just thought i’d throw that out there

Because they are really aliases for one another. They don’t do exactly what their name implies. (Which I do not like myself.) If the object is not in the selection set, the remove method will add it.

So, they actually are a toggle.

1 Like

Ok that makes sense. just wondered if it was a typo.

Sketchup::Camera#fov=

The “fov=” setter is documented in the API as taking an argument in millimeters. That is inconsistent with the “fov” getter method which returns a value in degrees. The “focal_length” getter and setters are in millimeters. A field of view should be expressed in angular measurements, and testing with it shows that it is working in degrees.

A simple test at the command line of:

Sketchup.active_model.active_view.camera.fov= 50.mm

results in a significant amount of magnification. A length of 50.mm, converts to a simple floating point value of 1.98, or almost 2 inches. The “fov=” is accepting that as 1.98 degrees.
One might try to say that 50.mm is a FOV for some sort of camera, but increasing focal lengths always zooms in more, while increasing FOV in degrees zooms out.

The API documentation for #fov= should be units of degrees.

When Sketchup’s built-in zoom tool is in use, the VCB (Value Control Box) can accept text in both degrees and mm, but the fov= is not working that way.

API:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/camera#fov=

I’ve been away from Sketchup for a while and find the current Ruby API documentation to be lacking. To start, I’m trying to create an Extension with a menu. But the documentation for menu is incorrect, it should include add_item not add_menu. And if I get a menu item id how do I access its methods and properties? What are its methods and properties?

You are right. The headers say add_menu, but the documentation text and examples say add_item! This is a documentation error.

The Ruby API is lacking in useful support for menu items. There isn’t much you can do with the id. If you created a UI::Command object for use as the menu item, you can retain a reference to it yourself and try invoking its methods. I’ve had no luck with this, however. It appears that most of the Command’s attributes are copied into some inaccessible structure as the item is added to a menu and changing them later has no effect.

We’ve had these issues for 8 years or more.

Recently the switch was made to use YARD, and a small group of us are in the process of an overhaul. It’ll take some time.

Thanks Steve. I thought there was a way to disable and enable a menu option
but don’t remember how. I seem to have lost all of my old code. That’s
where the Ruby API documentation is really lacking. The old documentation
was much better.

You use the beforementioned id: Sketchup::Menu#set_validation_proc

It is the old documentation. That’s the main problem. :wink:
(It is just being output by a different webpage building engine.)

Not what I remember. A menu item is an object, but what are the methods and what are the properties?

Of course it is, because Ruby is a 100% object oriented language.

As above, I had given you the link to it’s class page (but to a specific instance method.)
EDIT: Which was the wrong method. (Fixed previous link.)

Here is the plain class page link:

Dan,

My apologizes, set_validation_proc does work to enable or disable a menu option. I tried menu_object.methods and get a list of methods but can’t seem to call some of them. Probably missing parameters. That’s where know the properties would help.

Ruby uses inheritance (as well as composition.)

So you’ll see a bunch of methods inherited from the Sketchup::Menu class’ superclasses (and ancestral library modules.)

Sketchup::Menu.ancestors
#=> 
[ Sketchup::Menu, Object, PP::ObjectMixin, 
  JSON::Ext::Generator::GeneratorMethods::Object,
  Kernel, BasicObject
]

To see only the API methods, use:

menu_object.public_methods(false)

or

Sketchup::Menu.instance_methods(false)

(The false argument says not to include inherited methods.)

You won’t have any luck using standard Ruby methods on the API menu objects. They are just thinly wrapped C objects that are OS dependent. The Ruby Core doesn’t know anything about manipulating them. The API team has not exposed the underlying OS dependent C functions in the Ruby API.

But if your a OS system hack, you can use Win32API or Fiddle library to make system calls. (It requires knowledge of the OS system SDKs and C/C++. It is really off-topic for this thread.)

In the description of Geom::LatLong.to_s, there’s a typo – instead of “to_s”, there’s “to_a”.

■■■■ this forum needs better formating for code! :smile:
(Something like inline <pre>.)

RE: this forum needs better formatting for code! ... (Click to expand)

Use backtick delimters for inline code, ie:

… there’s a typo – instead of to_s, there’s to_a.

For blocks of code use triple backtick delimiter lines (with the language on the first line):

```ruby

  # some ruby code here
  def mymethod(args)
    puts args
  end

```

OR:

```javascript

function send_to_ruby(params) {
  sketchup.callbackName(params)
}

```

(The blank lines are not needed. The actual delimiter lines are there.)

1 Like

I don’t see that in.

I see no reference to .to_a at all.
It’s all .to_s in that entry.
I agree that the API docs are very far from perfect, but in this instance I see no errors ??

I do,… the to_s method’s docstring begins “The to_a method …”


:white_check_mark: FIXED

Doh!
I now see it in the first line of text - however, the rest of the example is correct…
Yet another typo !
:grimacing: