# Generate report from Ruby API

**URL:** <https://forums.sketchup.com/t/generate-report-from-ruby-api/191235>\
**Category:** Ruby API\
**Created:** [March 1, 2022, 10:24am UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235 "2022-03-01T10:24:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtamas](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mtamas](https://forums.sketchup.com/u/mtamas)\
**Post date:** [March 1, 2022, 10:24am UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/1 "2022-03-01T10:24:03Z")

</div>

Hello!

There is a “Generate Report” functionality in SketchUp. Is there any way to do this from Ruby API? I do not want to open that window, etc, just click on a button which generates the report file automatically. Could you provide an example code for this please? Thank you.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 1, 2022, 9:39pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/2 "2022-03-01T21:39:11Z")

</div>

> [@mtamas](#):
>
> There is a “Generate Report” functionality in SketchUp. … from Ruby API?

There is no dedicated API class (that I know of) to manipulate and run reports as this feature is a web-based platform. (The user must be connected to the internet to see the newest version of the interface with custom report builder. Otherwise the old local interface with hard set report options is shown.)

The reason they switched to web-based is so that they can update and improve it at anytime independent from the application’s update cycle.

You can open a feature request in the official API tracker:

- [Issues · SketchUp/api-issue-tracker · GitHub](https://github.com/SketchUp/api-issue-tracker/issues)

But I don’t think it would be anything more than firing off a predesigned report.

A more complex report API might stifle innovation in the generator and it’s interface.

> [@mtamas](#):
>
> I do not want to open that window, etc

There is no send action to open the window anyway. (We cannot use [`send_action`](https://ruby.sketchup.com/Sketchup.html#send_action-class_method) to send a command ID, because SketchUp assigns a command ID “on the fly” as it loads, so this ID can be different each time depending upon what other commands get loaded.)

A shortcut would need to be assigned to the menu command and then a key sender used to bring up the window.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 1, 2022, 9:46pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/3 "2022-03-01T21:46:39Z")

</div>

> [@mtamas](#):
>
> Is there any way to do this from Ruby API?

Not specifically the native SketchUp “Generate Report” feature, but creating text files and reports is one of the basic features of the core Ruby programming language.

There are numerous topic threads here about “walking” the model hierarchy and collecting information for export. (A text report written to a file is he simplest form of export.)

- [`IO`](https://ruby-doc.org/core-2.7.2/IO.html) class

- [`CSV`](https://ruby-doc.org/stdlib-2.7.2/libdoc/csv/rdoc/CSV.html) library class

---

<div class="post-metadata">

**Author:** ![mtamas](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mtamas](https://forums.sketchup.com/u/mtamas)\
**Post date:** [March 1, 2022, 10:08pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/4 "2022-03-01T22:08:29Z")

</div>

Thank you for your answer! Actually I need the dimension and the color of each component in the model saved to a CSV file.  
So I guess I should find the components somehow in the model and get their properties. Can you send the link of a thread where I can find information about how to “walk” the model hierarchy?  
I found this one: [Getting a list of Component from current collection](https://forums.sketchup.com/t/getting-a-list-of-component-from-current-collection/63545)  
but I don’t think this is what I need…  
Thank you!

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [March 1, 2022, 10:18pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/5 "2022-03-01T22:18:08Z")

</div>

> [@mtamas](#):
>
> Can you send the link of a thread where I can find information about how to “walk” the model hierarchy?

Sorry I’m busy for awhile. There are quite a few I’m sure. Learn to use the forum’s search feature and advanced search form.

---

<div class="post-metadata">

**Author:** ![michal.mk.kalinowski](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/michal.mk.kalinowski/32/223782_2.png) [@michal.mk.kalinowski](https://forums.sketchup.com/u/michal.mk.kalinowski)\
**Post date:** [July 28, 2022, 6:46pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/6 "2022-07-28T18:46:55Z")

</div>

I understand there is no way to run online Reports Generator in Ruby. But is there a way to run built in v1 generator in Ruby, so that we do not need to turn off internet connection if we want to do that? There are some limitations of online reports which result in need or using the built in v1 report…

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [July 28, 2022, 9:54pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/7 "2022-07-28T21:54:09Z")

</div>

I **cannot** find a send action to do this.

Perhaps there is something internal ? @tt_su ?

---

<div class="post-metadata">

**Author:** ![michal.mk.kalinowski](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/michal.mk.kalinowski/32/223782_2.png) [@michal.mk.kalinowski](https://forums.sketchup.com/u/michal.mk.kalinowski)\
**Post date:** [August 6, 2022, 1:09pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/8 "2022-08-06T13:09:11Z")

</div>

Or maybe some other Ideas to Generate Reports v1 without closing Sketchup, disabling internet conection and reopening Sketchup?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [August 6, 2022, 3:30pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/9 "2022-08-06T15:30:31Z")

</div>

A few days ago I tried it, and did not need to close SketchUp. Just disconnected my network cable and after the taskbar showed my internet connection was off, I did the report command and got the old v1 interface.

I do know how to send key stokes to SketchUp on Windows but not on mac. Some Mac users have used the `cliclick` utility on Mac to do keystroke macros. You would use it with Ruby’s `%x` command strings (which use the [global backquote](https://ruby-doc.org/core-2.7.2/Kernel.html#method-i-60) method.)

Here is one of J Boundy’s examples… (note, he no longer frequents these forums) …  
[Changing active\_entities within a tool - #3 by john\_drivenupthewall](https://forums.sketchup.com/t/changing-active-entities-within-a-tool/55420/3)

---

<div class="post-metadata">

**Author:** ![michal.mk.kalinowski](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/michal.mk.kalinowski/32/223782_2.png) [@michal.mk.kalinowski](https://forums.sketchup.com/u/michal.mk.kalinowski)\
**Post date:** [August 6, 2022, 4:07pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/10 "2022-08-06T16:07:46Z")

</div>

On a Mac I get a bug on the screen when I try to do it.

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/4/3/43448edf803ab607fc73ef036a48ab29d09d3686.jpeg)

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [August 18, 2022, 2:58pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/11 "2022-08-18T14:58:37Z")

</div>

> [@michal.mk.kalinowski](#):
>
> On a Mac I get a bug on the screen when I try to do it.

I did see this yesterday on my PC whist testing with my network cable disconnected. It was because of some error (which I think was due to either SketchUp thinking I was offline or network latency issues.)

Regardless …

> [@DanRathbun](#):
>
> There is no send action to open the window anyway.

…

> [@michal.mk.kalinowski](#):
>
> I understand there is no way to run online Reports Generator in Ruby.

**My bad !** There actually **is** , but I had forgotten. In another conversation about components I was reminded of previous posts I had answered in the Dynamic Components category.

There is a method that can be called to open the Generate Report interface window. Does not help much with automation as a person still needs to click buttons and and use the save file dialog to have a report file generated.

```ruby
$dc_observers.get_latest_class.show_reporter_dialog

```

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [August 18, 2022, 4:22pm UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/12 "2022-08-18T16:22:47Z")

</div>

> [@mtamas](#):
>
> I do not want to open that window, etc, just click on a button which generates the report file automatically.

Where would you wish to save these CSV report files ? (see comment below)

> [@michal.mk.kalinowski](#):
>
> But is there a way to run built in v1 generator in Ruby, so that we do not need to turn off internet connection if we want to do that?

**I did find a way to do this without the reporter interface.**

However, the v1 generation code does **not** honor a passed in filepath and always prompts the user for a file location and filename. It also is written so that the “Save As” dialog will open at the last location that the operating system thinks a `.csv` file was saved in.

@mtamas & @michal.mk.kalinowski …  
How much do you guys know about setting up a [`SketchupExtension`](https://ruby.sketchup.com/SketchupExtension.html) registrar script and folder hierarchy and creating toolbar button images ?

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [January 6, 2024, 1:33am UTC](https://forums.sketchup.com/t/generate-report-from-ruby-api/191235/13 "2024-01-06T01:33:57Z")

</div>

> [@DanRathbun](#):
>
> I did find a way to do this without the reporter interface.

Just an update to this topic. The workaround I found **cannot be posted** as it circumvents the reporter’s **Pro only** filter.

So, without permission from Trimble, I will not be posting the code.

This means coders will need to code their own model hierarchy walking iteration and build up the dataset to export to a CSV file.
