Open Generate Report window using ruby

Does anyone know if it’s possible to open the the Generate Report window using a ruby script?

I can’t test, because I’m on my smartphone, but I find this in my "old bookmarks ". I guess the “origin” is @DanRathbun, but at least he can tell more, for sure :wink:


Weirdly, when I do this in SU 2024, the dialog is blank.

When I open it manually from the File menu, it populates normally.

same for me, it opens blank

A lesson of reliance to undocumented interfaces.

Here is an alternative:

# encoding: UTF-8
# 'ScottinmanDCUI_main.rb'

require 'su_dynamiccomponents'

module Scottinman
  module DCUI

    extend self


    def show_reporter_dialog
      unless ::Sketchup.version.to_i > 21
        # UI::Command#proc method is SU2022 or higher:
        ::UI.messagebox('SketchUp 2022 or higher required!')
        return false
      return dc_not_loaded() unless defined?($dc_observers)
      get_generate_report_command() if GENERATE_REPORT.nil?
      if GENERATE_REPORT.nil?
        ::UI.messagebox("Could not find 'Generate Report' command!")
        return nil

    def dc_not_loaded
      UI.messagebox('Dynamic Components extension is not loaded!')

    def get_generate_report_command
      commands = ::ObjectSpace.each_object(::UI::Command).map(&:itself)
      found = commands.find {|cmd| cmd.menu_text == 'Generate Report' }
      const_set(:GENERATE_REPORT, found) if found

    if !defined?(@loaded)
      get_generate_report_command() if defined?($dc_observers)

      # Perhaps create a toolbar here with a button ?

      @loaded = true


Fire it like:


amazing! Works great

1 Like

Any reason this would not fire after closing and re-opening sketchup?

You could make an extension from the code, but otherwise you will need to run it in Ruby Console each time you open SketchUp.

1 Like

What Colin said.

I did not write the code to fire the show_reporter_dialog() method when the code loads, as you did not ask for this. I wrote it so it could “sniff out” the DC command at any time.

For example, even though the above code makes a require statement to have the Dynamic Components extension load first, a user could switch it off in the Extension Manager.
In this scenario there is no reporter command to “sniff out” so, a user would see the messagebox with the "Could not find 'Generate Report' command!" message displayed.

I made the assumption that you perhaps wanted to create a toolbar button to open Generate Report.

Is there a way then to just have a script so that I can put it into a custom button that I’ve created with the toolbar editor? Just looking to launch the report dialog window each time I run the script from a custom button

I put a comment near the bottom of the code where you can define a command object (and a dedicated toolbar if you wish.) The comment looks like …

# Perhaps create a toolbar here with a button ?

If you are using one of the toolbar editors it should be able to “sniff out” the command object.

Alternatively, since the DC extension would likely load first, the command could be added to the existing DC toolbar.

      toolbars = ::ObjectSpace.each_object(::UI::Toolbar).map(&:itself)
      found = toolbars.find {|tb| == 'Dynamic Components' }
      found.add_item(cmd) if found

Is there a way to launch the report window without having to have the DC extension loaded?

Interesting question I’ll need to think on.

There are two reporter dialogs. The old “offline” dialog that is implemented by the extension code and the newer online dialog which displays a server-side interface.

The command is added to the File menu by the extension I think. Testing …
Answer: Yes, I switched off the DC extension and the command is not implemented.

So, it looks like the extension still is needed to implement the command and create a dialog window to load the web interface.

Why would you not want the DC extension loaded ?

It seems to be working sporadically. I have the DC component extension installed, I tested the code using the ruby console but when I fire it says: Could not find ‘Generate Report’ command!

You are still running on SU2022?

Also, it is searching for the English name of the command. It will fail if SketchUp is run under a different language.

yes still running 2022. Its running on english

Well, I would need more to go on than this. What is different when it does not find the command?

Oh, (head smack) I see one major problem why you get the “cannot find command” issue:

The menu text for the command is "Generate Report..." not "Generate Report".

But it also seems like the command is checking the call stack and if it is not called from the DC code then the dialog is blank.

I have no problem adding icons to the “Generate Report” command and the command to the existing DC toolbar, it just won’t work.

The only thing that does work is setting a keyboard shortcut to the File menu “Generate Report…” command.

For example this edition will work if you create a F10 shortcut to the File menu “Generate Report…” command.

ScottinmanDCUI.rbz (3.5 KB)

Remove the old file from your “Plugins” directory.
If you wish to change the shortcut, see the Microsoft docs for the SendKeys method.
If you don’t like the icon create one yourself.

I believe I have found a convoluted way to add a button to the existing DC toolbar using the existing Generate Report command. It should also work for all languages.

See …

@Scottinman you can remove the above “plugin”. Any assigned keyboard shortcut can remain assigned. The generic extension does not use the shortcut nor interfere with it.

Also, the generic extension (linked above) has both old and new (post 23.1) iconography.