Tool or script to select all objects in a layer and make component

Hey all. I’ve been given a bunch of assets created in SketchUp but the original user only organized the model using layers. I will be exporting this to other software for rendering. Is there any tool or script you guys know about that will iterate through the model and make components out of all the objects on each layer. So for instance, all objects on layer “walls” will be made into a component called “walls?” Thanks in advance for your help!

I don’t envy you your job with this. I guess from what you describe, I would turn off the visibility for all but one layer at a time and then select the content that has that layer assigned to it (nothing is “on” a layer in SketchUp.) and make a group or component. Assign the same layer to the group/component in Entity Info. Turn off that layer and turn on the next. Select the entities and make a group/component. Rinse and repeat for the next layer. Make sure Layer 0 is the active layer for this whole process.

If I was given that job I would charge at least double. :wink:

2 Likes

This sounds like the way to go to me, and with shortcuts it would not be so bad. Start with all tags visibility off, so nothing visible, then turn one tag visibility on, command A to select all, shortcut key for make component, name, return. Next tag… Not automated but should go quick.

certainly.

1 Like

Yes, that is what I did for the first model ( a smaller one). I made all layers invisible(off) and went through one by one and turned them on and selected one face and then selected all on same layer. Then created component. Rinse, repeat.

I have some programming experience but not with sketchup or ruby scripts. Do you know if that is something that could be done via script?

I expect that even with a script there’d still be a fair amount of manual input involved to get things right.

Thanks.

Depends if the model already contains nested components.

To only consider geometry on the top level would be pretty easy.

Sketchup.active_model.start_operation('Components By Layer', true)
Sketchup.active_model.layers.each do |layer|
  group = Sketchup.active_model.entities.add_group(Sketchup.active_model.entities.select { |e| e.layer == layer })
  component = group.to_component
  component.definition.name = "Component: #{layer.name}"
  component.layer = layer
end
Sketchup.active_model.commit_operation
1 Like

Try Selection Toys from Extension Warehouse!

sel1

This adds the Select/All on Selected Layers command to the context menu.

sel2

Triple if there are nested components with different Tags! :stuck_out_tongue_winking_eye:

This works great. I just have to make sure to purge empty layers. Thanks!

There is a script for that as well.

Sketchup.active_model.layers.purge_unused
1 Like

Thanks. Delving into ruby scripts. A little different than what I’m used too.