When importing a model with code,how to remove this new nested group information?

When importing a model with code
Importing a model always automatically adds a new nested group information named after the model file name, how to remove this new nested group information?

require 'sketchup.rb'

def import_model(file_path)
  model = Sketchup.active_model
  status, imported_entities = model.import(file_path, true) # The parameter true means merge into the current model
  if status
    UI.messagebox("Model imported successfully!")
  else
    UI.messagebox("Failed to import the model.")
  end
end

import_model('C://Users//Administrator//Desktop//box.skp')

Even after importing it and blowing it up once, it didn’t work.

require 'sketchup.rb'

def import_model(file_path)
  model = Sketchup.active_model
  status, imported_entities = model.import(file_path, false)
  if status
    # If the import is successful, blow up the model immediately
    imported_group = model.entities.grep(Sketchup::Group).first
    imported_group.explode if imported_group
    UI.messagebox("Model imported and exploded.")
  else
    UI.messagebox("Failed to import the model.")
  end
end

import_model('C://Users//Administrator//Desktop//box.skp')

QQ图片20240529224827

Maybe just explode the component, and purge ?

In fact, I don’t even need to blow up and clean up these extra operations, just import the model and keep the original group information of the model.

Ah, ok. I misunderstood.

Hi - I’m having a similar issue - when I import a model exported from CAD software (Revit) in .ifc format, it comes in with a ton of nested groups and components that only weigh down the model and make it difficult to edit. Is there an extension or any way to eliminate these nested groups and components? I can’t be the only person to have this issue… THANKS!!!

You can try Curic Flatten to Object:

1 Like

If you flatten the hierarchy in SketchUp, you will not likely be able to export again to the same external IFC hierarchy. This is because context nesting is the only way that SketchUp can manifest the relationships for IFC (or any parent ↔ child object relationships.)

RE, “weigh down” does not really apply as the geometry is either in the component entities plural or all in one entities context singular.

YOU ARE AWESOME THANK YOU. bought you a coffee!!

THANK YOU CURIC4SU!!

Removing the 2084 components reduced the file size from approx 89MB to 26MB and allows me to edit each remaining component quickly - no longer need to dig deep (up to 4x nested components) to edit geometry.

Cleanup Statistics:

Materials Merged: 42
Purged Components: 2084
Purged Layers: 0
Purged Materials: 24
Purged Styles: 0
Skipped Locked Definitions: 0
Total Elapsed Time: 8s

You don’t need to dig. Use the Outliner panel to directly target any nested object for edit by double-clicking it in the object tree.

How do I find a 4x nested component in the outliner amongst 2000 components quickly?

There is a search box at the top of the Outliner panel.

If your instances and definitions have names, you can use the search filter to pare down the object list to whole or partial matches.


SketchUp User Guide: