Need help creating custom toolbar in toolbar editor for Chris Fullmer's Repeat Copy

Title pretty much says it all. Need help with the Ruby side of this problem. Would like to create a custom toolbar for myself with Toolbar Editor for Repeat Copy. Know absolutely nothing about Ruby and this is probably the only time I’d use it…

Thank you very much.

In that case we both would likely be wasting time.

First, try out Aerilius’ Toolbar Editor plugin. You can create custom toolbars, using extension commands*. (You cannot add native command buttons yet.)
* Provided that the author of the extensions followed normal programming practices.

That’s what I’m using - Toolbar Editor. According to the link you posted…“Click the “+” button on the right to create a new button. You can then write your own Ruby commands or paste a piece of Ruby code that you found on the forums.” Isn’t this how you’d add a custom button to a toolbar, for example, a way to add Repeat Copy (an extension that doesn’t have its own toolbar) to a custom toolbar? You can even add your own icon to it…

It can’t be too difficult to point the custom button to an extension command - similar to creating a hotkey for an extension command. I just don’t know Ruby. Was hoping someone had an example or quick explanation of how to do it.

Perhaps (I haven’t yet done this for someone else’s plugin.)

I was thinking about how you would look for the plugin’s commands in the right hand pane, and add the command to the toolbar. The command should appear in the list if a UI::Command object was created for it, or if the extension had a toolbar of it’s own.
(Check the toolbar list via View > Toolbars…)

But this is not the only way to launch plugin commands.
Some plugins just use menu items (either top level menus or right-click context menus.)

So, it depends upon how Chris programmed it. If it is going to require intimate knowledge of the code, then Chris should be the one divulging it, as this is a commercial plugin.

(I have sent an invite to him to participate in this topic.)

Maybe I’m missing something or a bit confused… Toolbar Editor has a plus button on the right to add your own button to a toolbar. When you click it, a new little window appears and you can add a name for the button, category (?), description, icon (you select it), and there is a box for Ruby code. Once saved, this new button is shown on the right hand side of the main Toolbar Editor window along with all of the normal available buttons. Now, if I can set a hotkey of Ctrl+R for the plugin Repeat Copy (yes, commercial and I’ve purchased it) then why can’t I write a little Ruby snippet that either calls on Repeat Copy directly or enters the keyboard command of Ctrl+R that I’ve assigned it? Seems like it should be really simple if you just know the Ruby command for it. I’ve been looking at Ruby script examples but haven’t found the right information yet.

Sorry, … I edited my previous post, as I can see how it looked like I was disagreeing with you.

All true. (I did not mean to make it look like this was untrue. I edited my previous post.)

… because it has created a native C++ menu item. The native Shortcuts panel (of the Preferences dialog,) enumerates menus and the items on them, on the native (C++) side of the code.

Aerilius’ Toolbar Editor is a Ruby extension, which is limited to using only whatever has been exposed to Ruby, by the SketchUp development team. (And not everything about the UI has been exposed to the APIs.)

So it is not really that they are like apples and oranges, … but rather they are both apples, but in different orchards. And one orchard is off limits.

As I tried to explain above, menu items can be, but do not have to be, exposed as Ruby UI::Command objects. There are older quick and dirty ways to create a menu item, that does not create a lasting interface. After the creation code ends (ie, goes out of scope,) there is no longer any way (via the SketchUp Ruby APIs) for the original programmer, any other programmer or plugin, to get a reference to these menu items.

If the original programmer just enclosed the plugin command code in the block for the add_item() method, then there is no way to execute that code other than clicking the menu item.

But a better form of coding would be to enclose the command’s code within a named method, and the menu item block or the UI::Command block simply calls that named method. (A method is known as a function or procedure in other languages.)

Of course it would be. But first, you need to get all the extension programmers to adhere to some standard, when it comes to writing their UI interfaces. Sounds simple, but in practice it is not. Such standards have been proposed but everyone just has their own style, and it is like pulling teeth to get everyone to agree on one single standard.

When I write an extension with multiple commands, I like to expose them in a collection called “Commands” (usually a hash with the command name as the key.)

But the authors of some commercial extensions do not do this, and may not want any other extension calling their commands. There is history where plugins have been collected and packaged, without the owners’ permissions, and distributed with a “collection toolbar”.


Now, the Ruby language has built-in methods for introspection and reflection. It may be possible to use these method calls, to interrogate the Ruby objectspace, in order to deduce what the namespace object name is that is wrapping Chris’ extension, and then interrogate it to list it’s method names. Possibly you could then figure out what the name of the “Repeat Copy” command method is, and then use a fully qualified method call in for your custom toolbar button.
Ex:

ScottsModule::NiftyPlugin.do_some_command()

But this requires that the extension, (to be interrogated,) be loaded.

I do not have it, and I am not going to go pay ten dollars just to answer your question.

So, this is why it is best for Chris to give you the answer on what the method call snippet is.

Because usually, actual plugins / extensions do not use introspection methods. It is something done by programmers at the console. (Window > Ruby Console)

You need to refer to the Ruby Core documentation for the Kernel module, Object, Module, and Class classes. (Kernel is included into Object, which is the mother of everything. So everything else inherits their methods. Class is the subclass of Module so all classes inherit methods from class Module.)

Thank you for the in-depth explanation. Really appreciated. Still seems like it should be simple…and yet not so much now. I guess I will have to stick with shortcuts and menu searching (too many programs and too many shortcuts/hotkeys to remember - ugh).

1 Like