Ruby code to import component into model from custom HTML pop up box

Thanks for that, looks exacty what I need!

Also, Dan, your Facesniffer / Menu finder looks like it would also be useful. Can you post on here when its ready for download?
Will it have a function whereby it will show the most recent folder navigated to as an item on the menu? (That will save a lot of time navigating to a certain folder eg. cabinet style, each time).

Menus are permanent for the session. And the Ruby references go out of scope after the file gets done evaluating, so we cannot reuse them, for example to add more submenus or menu commands later on. (By the way, we have for many years pleaded for persistent menu object references.)

So, the folder path(s) need to be known when the extension is loading. In the old version, I had the program path (the distributed components) and the user components path hardcoded as the only two paths.

I was thinking of adding two more. Ie, the user can change the normal user path via the Preferences Files panel to point somewhere else (and this is usually done when keeping a collection independent of SketchUp versions.) I had not parsed the settings file to see if the user did this in that old quick and dirty example.
The second path (or extra paths) can be added at any time by having the user select a directory.

I also never dealt specifically with MacOS paths in that version.

Now, I can put a “Get Component from Last Folder” command that leverages MS Windows Most Recently Used paths that get automatically saved because SketchUp API’s file browser panels use the system file browse dialogs. The method for such a command might look like this:

module SomeAuthor::SomePlugin # <--<<< within your extension submodule

  extend self

  def get_component( multi = false )
    if defined?(@mru_skp_path)
      filepath = UI.openpanel(
        'Choose Component', @mru_skp_path, 'SketchUp Model|*.skp||'
    else # Let MS Windows open the last path used for .skp files.
      filepath = UI.openpanel('Choose Component', '*.skp')
    return unless filepath
    # UI::openpanel still returns paths with backslashes!
    # At this point we could also save a reference to this path.
    # Sort of our own Most Recently used path:
    @mru_skp_path = File.dirname(filepath)
    model = Sketchup.active_model
    deflist = model.definitions
    comp = deflist.find {|cdef|
      next false if
      slash(cdef.path) == filepath 
    if comp # already loaded into DefinitionList
      model.place_component(comp, multi)
        comp = deflist.load(filepath)
      rescue => err
          'Error loading component:'<<
        model.place_component(comp, multi)

  def slash(filepath)


Try creating a “Get Component” UI::Command for this and assign it to a toolbar button.

Let me know how it works for ya’

@DanRathbun Something ‘clicked’ with one of your comments above. I was building a menu and a toolbar, either of which redundantly opened DCs. I prefer the toolbar for usability… but it was going get too big as I built it out. So, I fiddled around and built toolbar launchers from the menu. I also added a “Tools” activator… featuring the Face Area Sniffer and @dezmo tag by component name. Thanks to both of you for posting the helpful examples.


Oh, … now that’s a good idea!

You could also have floating child toolbars launched from parent toolbar buttons. Each of the commands on the child could close it’s toolbar, so it functions similar to a flyout toolbar. (Which by the way, API consumers also asked for many years ago.)

@DanRathbun I gave it a shot:

That little bit of goofing around reminds me of one thing that I mean to go back to (because I can’t get it to work): the show DC Options and Attributes. My results with that have been hit or miss but having the panels pop-up when DCs are grabbed from the menus would be handy. I wonder if that could be a toggle option.

I had the DC Options popup feature in my example. But after doing a forum search, I realize now that I had not publicly posted it back then (OCT of 2019.) I had only sent a “private labeled” edition (ie, where the toplevel “Example” module is properly renamed) via a PM to the user. I’ve made a few edits since then.

I never had a toggle command to switch off the DC Options popup. It was just on all the time (in this example) but I have other examples that have a similar toggle and can paste code from one of those I’m sure.

I’ll try to get it posted later today. (The lawn needs mowing this morn before it gets too hot. Supposed to be 92 today with the typical afternoon t-storms we get in FL in the summer.)

A bit of progress today. First, the toolbar launcher had to make friends with ‘if loaded’.

A definite move from not good to less un-good.

I rooted around and found some of your code. It may be what you were referring to. But if not, it’s still a handy little deal.

Maybe this thread ought to be continued elsewhere?

Had issues yesterday with my computer relocating the AppData path, so I did not get the example finished.

Hard to tell without a link. wait … I think this is the one of I was thinking of:
Dynamic Component Options window "Opened" when new drawing opened - #4 by DanRathbun

It has methods from other examples and yesterday I pasted from this to the menu example.

Yes, you linked the one I used. Previously I had tried using the code in this thread:
Close Component Option & Component Attribute windows using ruby script - Developers / Ruby API - SketchUp Community

… oh my, my examples are … everywhere! :wink:

Maybe something like this?: Ruby SketchUp API Examples - Developers / Ruby API - SketchUp Community

No. I was kidding. Having multiple posts (and partial posts at that) is not so good for maintenance.
I do have them (mostly) in one “Examples” folder locally.

As far as links to example posts go, I rather have such a list in my Ruby Resources collection. Probably in the Ideas categorical list, as that list is pinned to the top of this category.

You can find some of these by searching for “[Example]” or “[code]” prefixes.

RE, Dynamic Components snippets and examples I had mostly posted in it’s category as most were in answer to questions posted. BTW, I also have a Dynamic Components Resource list (that is no longer pinned.)

Deleted the post. Can’t seem to find a way to delete the topic.

Just thought I’d gather things up and post as I ferret around.

It takes the system a while to delete. A day or so. (It allows the sages & admins time to have a look in case it was something nefarious that needs disciplinary action.)

The only nefarious I’ve done is create a topic and then change the name to “Opps, can’t delete this topic”. But I also discovered that I can’t find a good place to collect ruby scripts. I like the Summary & Hide format option along with the syntax highlighting and ability to link to the context discussion available in posts here.

You haven’t. You’d know if you did. I mean something either nasty to get suspended (in the “dog house”) or legalistic to get booted from the forum permanently. (It has happened.)

The major issue with trying to put them all in one topic thread, is that newbs to the forum start discussions about various examples all in that one thread, instead of posting in the specific example thread or starting a new related topic. (The latter is kind of hidden. It’s the “+ New Topic” button on the bottom of the “Share Link” popup.)

Anyway, what happens is, we often wind up with concurrent intertwined discussions about different code issues which makes the discussion confusing.

I can compile a “cookbook” (I’ve even have the empty markup file) but I haven’t got to it yet as other help files take precedence.

Meanwhile, for your own use, you can bookmark any topics or posts and give the bookmarks a subject for later filtering or searching.

  • To bookmark a post click it’s button and you’ll see the bookmark button.
  • To bookmark an entire topic, go to the bottom (click the END key) and you’ll see the Bookmark button for the topic.

The boolmark icon looks like a gray edition of the red bookmark below:

  • :bookmark:

Then, later to browse or search your private stash of forum bookmarks, go to your avatar menu at the top right and you’ll see the bookmarks tab. To access the full listing, click the down arrow at the bottom of the menu list. (Hint: You can also create an internet shortcut aka browser bookmark to any of your private profile pages.)

The forum is not set to allow us to share our forum bookmarks from what I can see or the forum doesn’t have a bookmark sharing plugin installed. So for instance, I cannot share my booksmarks with anyone.

Just joking a bit. But dang that topic with no post does seem a suspect, almost criminal :slight_smile:

I did refrain from posting code because my code would just be bad examples to follow (causing confusing). And I get the idea of creating more threads that may move from definitive (the linked post) to less useful chatter (because I can’t answer most questions on the code or posts that I’d link).

I do bookmark some posts. I had also been saving links in an acknowledgement section as a comment at the bottom of ruby code. But that proved to be a poor way to go about it.

There was a “Create Wiki” option in the topic editing page. I didn’t want to further set in stone the very thing I was trying to delete but now that you point out some of the problems of creating a post with code snips and links it occurs to me that the Wiki option may allow turning off commenting. Of course you are creating resource wikis so it may seem that I am recreating the wheel. But I’m seeing people creating places (often, galleries) where they put their creations and maybe I should just make a spot like that but using a wiki. The reason I want to gather up the code is that I bump into stuff that I find useful and want to have it ‘at the ready’ as I try to understand it. I have to think this over for a while.

No, it does not. Evidence that at least two posts were added to the bottom of my Ruby Resource wiki thread, instead of either PMing me or starting a separate related topic to discuss some specific resource.

I might have mentioned this, but I will eventually clone the Ruby Resource lists here to one of my GitHub Pages.

Except that it’s their creations they are displaying.

And again, I already have some links to examples in the Ruby Resource wikis. They are currently (I think) in the Ideas list.

Maybe I should add a dedicated Examples and/or Snippets list ? The problem with the latter is that snippets are very numerous. And we would also wind up with snippets being shown out of context. I feel it is better to let the needy search the forum on the subject they are interested in.

For now, I suggest starting a “Snippets” folder on your local machine with a shortcut to it on the Desktop or taskbar, etc.

I have long had this. But it has gotten so large that I’ve begun making categorical subfolders.

Ah. It’s a double dangnabbit.

I do search around and collect. But it can be frustrating.

My feelings on the matter

what about bob i need i need - Bing video