Plugin: Create a Tag per selected component

Hi guys,

I am working on a model with many components at the moment and now comes the dreaded part of creating the Layout document specifying each component. So I was wondering - is there a plugin or something that creates a unique Tag/Layer for each selected component and places the component on that layer.

That would make it super easy to modify which parts to show and which parts to hide in Layout.

I can do this by hand of course but it feels like an task for a trained monkey that needs punishment.

I made some…first for test. To see if it is what you want?
No warranties! Use your own risk! But it should work…:wink:

See animation below too:

  1. Open Ruby console and copy-paste the code below to it and hit Enter (Return)
  2. If you select something and it contains one or more components, you will get a context menu (right mouse click) “Add Tag/Layer to selected comps by def name”
    The component instances will get a Tag/Layer association, where a Tag/layer name same as the component definition name.
    You can undo it.

See animation:(Click on it if not animating…)
tag_by_comp_name


module Dezmo
module TagByComp
  extend self
  @@loaded = false unless defined?(@@loaded)

  def add_Tag_to_comp_by_name
    mod = Sketchup.active_model
    sel = mod.selection
    layers = mod.layers
    mod.start_operation("Add Tag/Layer to selected comps by def name", true)
    sel.grep(Sketchup::ComponentInstance){|e|
      def_name = e.definition.name
      layer = layers.add(def_name)
      e.layer = layer
    }
    mod.commit_operation
  end
  
  unless @@loaded
    UI.add_context_menu_handler do |context_menu|
      if Sketchup.active_model.selection.grep(Sketchup::ComponentInstance).first
        context_menu.add_item("Add Tag/Layer to selected comps by def name"){
          add_Tag_to_comp_by_name()
        } 
      end
    end
    @@loaded = true
  end
  
end
end
2 Likes

Yo Dezmo! Whoa - this does EXACTLY what I needed!! So much time saved. And you just wrote this “like that” for breakfast? Amazing!!!

Can you imagine how Layout would excel if they would finally give the community the ability to write plugins for that beast?

Consider making this a plugin - I mean - I’m happy as Larry (however happy he may be) now but this might solve issues for some other folks as well. :slight_smile:

Again - thank you SO much!!!

You are welcome! I will wrap it to “real extension” later today , and post the .rbz file here. It will be unsigned , but you can install as usual.
(most probably will happen at the evening, EU time)

Nice. I’ve been using Sketchup since - I think 2008. We are a small boat yard somewhere close to Berlin - building all sorts of stuff that was designed in Sketchup - here an example of one of our latest projects - so you know what it goes into. :slight_smile: Lot’s of detailing ahead of me - this baby needs to swim by March next year…

![Kiebitzberg-Projekt-Antares|690x417](upload://4G


6uT3Wzwv08nM6wJ8F0YmLP4U1.jpeg)

4 Likes

If she will swim in Elbe I will check it near to Hamburg… :wink:

You can easily make Tag folders in version 2021 by typing the search string and then hit the +folder icon.

Here we are:
tbc

Dezmo_tag_by_comp.rbz (10.4 KB)
Create Tag/Layer and associate to selected component instances by it’s definition names.

  • There will be no “main” menu but a toolbar icon and context menu.
  • If you select something and it contains one or more components, you will get a context menu (right mouse click) “Add Tag/Layer to selected comps by def name”
  • The toolbar icon will be enabled with a similar manner.
  • Shortcut can be assigned, considering the above mentioned selection criteria.
  1. If there is a Tag/Layer already in a model it will be considered and used.
  2. If the Tag/Layer is already associated to instance there will be no changes.
  3. If the component instance definition renamed, you have to run the plugin again to get it’s Tag/Layer again, however the “old” Tag/Layer will not be removed. You can purge it yourself.

No warranties! Use your own risk! But it should work…:wink:
Bugs can be reported here. I’ll do my best, considering priority of my private life!

Good luck! Have a healthy time!

4 Likes

It’s beautiful. It’s also - the more I think about it - a perfect workaround for an absolutely silly shortcoming of the Sketchup/Layout workflow. WHY do you need to write this? :slight_smile: I mean - we already have the outliner and we already know all the components. The only reason this marvelous plugin is necessary is because you cannot hide / unhide elements from the outliner in Layout. So here I am hoping that this plugin will be obsolete one day. For now - it will save me hours on many days to come!

That’s actually a really useful hint! I did NOT know that. Makes a ton of sense!

This plugin IS beautiful. This is even better than writing Tag name directly into the Entity box which I was freaked out didn’t work suddenly in SU 2021.1. Nice work, Dezmo, thank you!

1 Like