• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

[REQ] Delete groups with just groups in them

Scheduled Pinned Locked Moved Plugins
7 Posts 2 Posters 542 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    Pixero
    last edited by 23 May 2016, 09:31

    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.
    group within group.jpg

    Group within group.skp

    1 Reply Last reply Reply Quote 0
    • D Offline
      driven
      last edited by 23 May 2016, 13:33

      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

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • D Offline
        driven
        last edited by 23 May 2016, 14:46

        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

        learn from the mistakes of others, you may not live long enough to make them all yourself...

        1 Reply Last reply Reply Quote 0
        • P Offline
          Pixero
          last edited by 24 May 2016, 08:19

          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?

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by 24 May 2016, 10:19

            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

            learn from the mistakes of others, you may not live long enough to make them all yourself...

            1 Reply Last reply Reply Quote 0
            • P Offline
              Pixero
              last edited by 24 May 2016, 10:59

              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.

              1 Reply Last reply Reply Quote 0
              • P Offline
                Pixero
                last edited by 24 May 2016, 11:42

                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.

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  1/7
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement