Create Own Buttons/Toolbar for Extensions


#1

Today I installed a bunch of plugins that will help me with my workflow. However I soon descovered some of them do not have a toolbar/button developed for them. I’d prefer them to be on a toolbar rather than under the Extensions menu at the top.

Is it possible to create my own buttons for the extensions I’ve installed? I googled for this solution extensively today but never got a concrete answer.

(I’m currently using SketchUp Pro 2018. I’ve also tried the ToolBar Editor plugin but it required me inputting the Ruby code myself)


#2

I don’t think there currently is a way to achieve this without writing any Ruby code. Creating an extension that allows people to do this without writing code of their own is in theory possible but would take quite a lot of work and bend the rules of what plugins are allowed to do (it would need to override SketchUp’s API method for adding menu entries to get a reference to whatever the other plugins do). @Aerilius’s LanchUp already does that, but rather than letting you create custom toolbars for the commands it lets you search them.


#3

That’s a shame… some of the tools would be so useful as a one click button as opposed to searching through the drop-down menu. This may be a stupid question but is there a way to retrieve the Ruby code manually for the simple purpose of pasting in to the box provided by ToolBar Editor plugin?


#4

What you can do is choose which toolbar buttons to use and how to combine them when the extensions you use already have toolbar buttons:

https://sketchucation.com/pluginstore?pln=ae_ToolbarEditor


#5

You can give then keyboard shortcuts.


#6

What you can do is choose which toolbar buttons to use and how to combine them when the extensions you use already have toolbar buttons

I’ve already looked at the Toolbar Editor and unfortunately it doesn’t help accomplish what I’m after; the extensions I’ve installed don’t have a toolbar button scripted so they don’t appear for selection.


#7

You can give then keyboard shortcuts.

This is a good option - I’ll just have to remember what keyboard shortcut I assign!


#8

You can search the plugins for add_item. The code typicaly looks something like this. The code inside the curly brackets after add_item is the code that is executed when the entry is clicked.

UI.menu("Draw").add_item("My Procedure") {
  UI.messagebox("My Procedure")
}

The code can also look like this. Here the add_item method references a command object nammed cmd. In that case, find the command object and copy the code within its curly brackets.

cmd = UI::Command.new("My Procedure") {
  UI.messagebox("My Procedure")
}
cmd.menu_text = "My Procedure"
UI.menu("Draw").add_item(cmd)

Notepad++ has a nice Find in Folder feature that can search multiple files at once.

This only works if the source isn’t scrambled though.


#9

Thank you for the explanation and the examples.

# Select entities first...
### i.e. pick or filter what you want cp'ing first...
### Original by Jim ### 'All' version made by TIG...
UI.menu("Plugins").add_item("Add Centerpoint"){
  model=Sketchup.active_model
  entities=model.active_entities
  selection=model.selection
  model.start_operation("Add Centerpoint")
  selection.to_a.each{|e|entities.add_cpoint(e.bounds.center)}
  model.commit_operation
}
###

Following your advice would I put:

“model=Sketchup.active_model
entities=model.active_entities
selection=model.selection
model.start_operation(“Add Centerpoint”)
selection.to_a.each{|e|entities.add_cpoint(e.bounds.center)}
model.commit_operation”

in to the Ruby console?


#10

Typically the add_item method reference a method but in this example the whole business code is defined within the menu entry. I’m not familiar with ToolBar Editor but if it supports custom Ruby code (and doesn’t have restrictions on length) this should work.


#11

NO, you’d paste it into the Toolbar Editor’s command creation dialog.


#12

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.