[REQ] Delete groups with just groups in them
-
I'm looking for ways to clean imported models that have multiple nested groups in them which make them hard to work with.
Would it be possible to have a plugin go through the model and check if there are nested groups /components with nothing but a group inside it and if so delete the top group?
Here's a small stripped example how it comes into SketchUp.
-
a quick reply
# grps without edges contain only sub-grps... if gents.grep(Sketchup;;Edge) == [] # exploding non_manifold, allows same context compares, but you loose the hierachy if !e.manifold? e.explode end next if e.deleted?
I'll have a look at your skp later...
john
-
this is stripped out of one of mine and may still have a few 'extras' you don't need...
it explodes the edgeless groups and removes the coplanar edges from the faces...
# digs deep into nesting and removes stuff... model = Sketchup.active_model defs = model.definitions ents = model.active_entities ########################## model.start_operation('Clean Import') # remove unwanted support geometry ents.grep(Sketchup;;SectionPlane){|sp| sp.erase!} ents.grep(Sketchup;;ConstructionPoint){|cp| cp.erase!} ents.grep(Sketchup;;ConstructionLine){|cl| cl.erase!} ents.find_all do |e| # keep any raw geometry... next if e.class == Sketchup;;Edge or e.class == Sketchup;;Face # remove previous 'sections cuts' ... e.erase! if !e.layer.visible? or e.definition.name.include?('-Section') next unless e.valid? # remove hidden geometry ents.erase_entities(e) if e.respond_to?(;hidden?) and e.hidden? next unless e.valid? if e.class == Sketchup;;ComponentInstance || e.class == Sketchup;;Group # sub-groupings gents = e.entities if e.class == Sketchup;;Group gents = e.definition.entities if e.class == Sketchup;;ComponentInstance # remove unwanted nested support geometry gents.grep(Sketchup;;SectionPlane){|sp| sp.erase!} gents.grep(Sketchup;;ConstructionPoint){|cp| cp.erase!} gents.grep(Sketchup;;ConstructionLine){|cl| cl.erase!} # remove coplaner edges... gents.grep(Sketchup;;Edge) do |e| e.erase! if e.valid? && e.soft? && e.faces.length == 2 && e.faces[0].normal.dot(e.faces[1].normal)>0.9999999999999 end next if e.deleted? # grps without edges contain only sub-grps... if gents.grep(Sketchup;;Edge) == [] # exploding non_manifold, allows same context compares, but you loose the hierachy if !e.manifold? e.explode end next if e.deleted? end end # e.class end # ents.find_all do model.commit_operation # 'Clean Import'
john
-
Thanks!
I've tried that last one on one of the example scenes from Revit and it worked but it took about an hour to run.
Is there any way to speed it up? -
you should have mentioned revit, before my computer broke…
it's possibly quicker as this one was really for working with unknown skp files...
in the ifc cleanup script I target the wrappers first by type name…
there's some excerpt's I posted on the SketchUp forum, showing adding materials, moving some to layers and hiding, etc…
hopefully I can rescue my hard drive as I haven't made a backup for ages…
john
-
Ok. I'll search that forum for your post then.
Edit: Can't find it. Perhaps a link...?
Actually I'm not using IFC but a Free Revit to OBJ exporter plugin and then Fluid interactives OBJ importer plugin for testing ways to get a Revit models into SU with Materials preserved.
As you know dwgs don't preserve materials but get the geometry nice and cleanly grouped.
My tries with IFC havn't been that good so looking for alternatives now...
And good luck with your harddrive. -
I commented away all that stuff i didn't need and now it was superfast. Less than a second on the same model.
Will try with the deleted coplanar edges added and see how fast it is...Edit: Nope, that took a great while. Tried again with just the remove groups part and then Thomthoms CleanUp and that finished in some 30 seconds.
Advertisement