sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Cleaning up after intersect_with

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 3 Posters 301 Views 3 Watching
    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.
    • L Offline
      lovebob
      last edited by

      I've been working with intersect_with recently, and after much trial and error got something working.

      I've been trying to make a hole of one shape inside another.

      The problem is if I delete the cutting group used in intersect_with, it deletes all the interior faces, which kind of defeats the purpose. But if I don't delete the group, then I have to carefully delete and clean up the cutting shape and everything by hand, which also is not good, since I'm trying to handle all this programatically.
      Specifically, if I do 'cutgroup.erase!' instead of 'cutgroup.explode' then I don't have any of the star's faces left, which is bad. I want to have a star shaped tube through the cylinder, not just a star shaped hole into the cavernous interior of the cylinder.

      What are other people doing to clean up after doing intersect_with ?

      model = Sketchup.active_model
      entities = model.entities
      entities.clear!
      
      # Draw a cylinder                                                                                                                                                                                        
      basegroup = entities.add_group
      basegroupentities = basegroup.entities
      center_point = Geom;;Point3d.new(0,0,0)
      normal_vector = Geom;;Vector3d.new(0,0,1)
      radius = 10
      edgearray = basegroupentities.add_circle center_point, normal_vector, radius
      first_edge = edgearray[0]
      first_edge.find_faces # needed to create face between edges                                                                                                                                              
      main_face = first_edge.faces.first
      main_face.reverse! if main_face.normal.z < 0
      main_face.pushpull 10
      base_trans = basegroup.transformation
      
      # Create the star                                                                                                                                                                                        
      cutgroup = entities.add_group
      cutgroupentities = cutgroup.entities
      star_z = 0
      pt1 = [0, 1, star_z]
      pt2 = [-0.351, 0.509,  star_z]
      pt3 = [-0.951, 0.309,  star_z]
      pt4 = [-0.488, -0.209, star_z]
      pt5 = [-0.588, -0.809, star_z]
      pt6 = [ 0.0, -0.409,   star_z]
      pt7 = [ 0.588, -0.809, star_z]
      pt8 = [0.488, -0.209,  star_z]
      pt9 = [ 0.951, 0.309,  star_z]
      pt10 = [0.351, 0.509,  star_z]
      base = cutgroupentities.add_face(pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10)
      base.reverse! if base.normal.z < 0
      base.pushpull 11
      cut_trans = cutgroup.transformation
      
      puts cutgroupentities.count
      puts basegroupentities.count
      cg = cutgroup.entities.to_a
      bg = basegroup.entities.to_a
      puts cut_trans.inspect
      puts base_trans.inspect
      puts cutgroupentities.count
      puts basegroupentities.count
      puts bg.size
      puts cg.size
      
      Sketchup.active_model.entities.intersect_with true, cut_trans, basegroup.entities, base_trans , true, bg
      
      
      cutgroup.explode
      basegroup.explode
      
      
      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Did you post a similar question over at StackOverflow?

        Btw, your profile says "SketchUp version: pre-6" - are you really using a SketchUp version older than 6?

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • L Offline
          lovebob
          last edited by

          I have not posted a similar question on StackOverflow, I thought I would be more likely to get an answer here.

          I'm using Sketchup 8.0.16845 on OS X. Whatever is in my profile is what the defaults are I guess, I only signed up last week and this is my first post.

          I am pretty familiar with Ruby but have only very recently discovered that Sketchup has a Ruby API and started playing around with that.

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            Maybe this can be done using intersect_with but it is certainly not necessary.

            model = Sketchup.active_model
            entities = model.entities
            entities.clear!
            
            center_point = Geom;;Point3d.new()
            normal_vector = Geom;;Vector3d.new(0,0,1)
            radius = 10
            edgearray = entities.add_circle center_point, normal_vector, radius
            main_face = entities.add_face(edgearray)
            main_face.reverse! if main_face.normal.z < 0
            main_face.pushpull 10
            star_z = 0
            pt1 = [0, 1, star_z]
            pt2 = [-0.351, 0.509,  star_z]
            pt3 = [-0.951, 0.309,  star_z]
            pt4 = [-0.488, -0.209, star_z]
            pt5 = [-0.588, -0.809, star_z]
            pt6 = [ 0.0, -0.409,   star_z]
            pt7 = [ 0.588, -0.809, star_z]
            pt8 = [0.488, -0.209,  star_z]
            pt9 = [ 0.951, 0.309,  star_z]
            pt10 = [0.351, 0.509,  star_z]
            base = entities.add_face(pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10)
            base.reverse! if base.normal.z < 0
            base.pushpull 10
            
            

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @lovebob said:

              I am pretty familiar with Ruby but have only very recently discovered that Sketchup has a Ruby API and started playing around with that.

              I've not yet had time to test your code sample, but as an aside note - check out this summary about writing SketchUp plugins: http://www.thomthom.net/thoughts/2012/01/golden-rules-of-sketchup-plugin-development/

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • L Offline
                lovebob
                last edited by

                Thanks sdmitch, that's a much easier way to do that!

                I should have asked what I really wanted to know instead of providing a simplified example.
                FYI this is all in the context of me wanting to make some things to 3d print.

                Two questions really,

                1. In the following code, is there a way to automatically remove the 3d text after doing the intersect so that I'm left with a solid rectangle that has the letters "Bob" punched through it?
                
                model = Sketchup.active_model
                entities = model.entities
                entities.clear!
                
                #Create a group to collect all entities for base cube                                                                                                                                                    
                basegroup=entities.add_group
                basegroupentities=basegroup.entities
                p1 = Geom;;Point3d.new(0, 0, 0)
                p2 = Geom;;Point3d.new(7, 0, 0)
                p3 = Geom;;Point3d.new(7, 4, 0)
                p4 = Geom;;Point3d.new(0, 4, 0)
                points = [p1,p2,p3,p4]
                base = basegroupentities.add_face points
                base.reverse! if base.normal.z < 0
                base.pushpull 1
                base_trans=basegroup.transformation
                
                cutgroup = entities.add_group()
                cutgroup.entities.add_3d_text('Bob', TextAlignCenter, "Arial", true, false, 3.0, 0.0, 0.0, true, 1)
                transform = Geom;;Transformation.new(Geom;;Point3d.new(0.5,0.5,0))
                entities.transform_entities(transform, cutgroup)
                
                cut_trans = Geom;;Transformation.new(Geom;;Point3d.new(0,0,0))
                intersections = Sketchup.active_model.entities.intersect_with true, cut_trans, basegroup.entities, base_trans , true, basegroup.entities.to_a
                
                cutgroup.explode
                basegroup.explode
                
                model.active_view.zoom_extents
                
                1. I feel like these two are related. In this example I get close to what I want but the new faces created by the intersect_with remain on the cylinder, and when I delete them by hand I'm left without any faces inside the cylinder, which I think means the cylinder is not watertight and will not print. I want to delete all the faces outside the cylinder but retain the ones created by the intersect_with command inside the cylinder.
                
                model = Sketchup.active_model
                entities = model.entities
                entities.clear!
                
                basegroup = entities.add_group
                basegroupentities = basegroup.entities
                center_point = Geom;;Point3d.new(0,0,0)
                normal_vector = Geom;;Vector3d.new(0,0,1)
                radius = 1000
                edgearray = basegroupentities.add_circle center_point, normal_vector, radius
                main_face = basegroupentities.add_face(edgearray)
                main_face.reverse! if main_face.normal.z < 0
                main_face.pushpull 1000
                base_trans = basegroup.transformation
                
                
                cutgroup=entities.add_group
                cutgroupentities=cutgroup.entities
                p1 = Geom;;Point3d.new(500, -50, 500)
                p2 = Geom;;Point3d.new(1500, -50, 500)
                p3 = Geom;;Point3d.new(1500, 200, 500)
                p4 = Geom;;Point3d.new(500, 200, 500)
                points = [p1,p2,p3,p4]
                base = cutgroupentities.add_face points
                base.reverse! if base.normal.z < 0
                base.pushpull 1000
                cut_trans=cutgroup.transformation
                
                baz = Sketchup.active_model.entities.intersect_with true, cut_trans, basegroup.entities, base_trans , true, basegroup
                
                basegroup.explode
                #cutgroup.explode                                                                                                                                                                                        
                model.active_view.zoom_extents
                cutgroup.erase!
                
                
                

                Any ideas on how to automate these processes?
                Thanks!

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  The Pro version of SketchUp 8+ has solid boolean operation that let you add and subtract from solid meshes. If you could use them then it'd simplify things a lot instead of using intersect and manually cleaning up.

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • L Offline
                    lovebob
                    last edited by

                    @thomthom said:

                    The Pro version of SketchUp 8+ has solid boolean operation that let you add and subtract from solid meshes. If you could use them then it'd simplify things a lot instead of using intersect and manually cleaning up.

                    That's true but it costs 500 bucks too, so rather than do that I think I'd just learn blender or openscad or something.

                    I already know Ruby pretty well, so my preference is to use Sketchup, but if it's not possible to accomplish the equivalent of the 'subtract' functionality using the Ruby API in the free version then I guess I'll have to move on.

                    1 Reply Last reply Reply Quote 0
                    • sdmitchS Offline
                      sdmitch
                      last edited by

                      This seems to work with or without using intersect_with

                      model = Sketchup.active_model
                      entities = model.entities
                      entities.clear!
                      
                      #Create a group to collect all entities for base cube
                      basegroup=entities.add_group
                      basegroupentities=basegroup.entities
                      base_trans=basegroup.transformation
                      p1 = Geom;;Point3d.new(0, 0, 0)
                      p2 = Geom;;Point3d.new(9, 0, 0)
                      p3 = Geom;;Point3d.new(9, 4, 0)
                      p4 = Geom;;Point3d.new(0, 4, 0)
                      points = [p1,p2,p3,p4]
                      base = basegroupentities.add_face points
                      base.reverse! if base.normal.z < 0
                      base.pushpull 1
                      
                      cutgroup = entities.add_group()
                      cut_trans = cutgroup.transformation
                      cutgroup.entities.add_3d_text('Bob', TextAlignCenter, "Arial", true, false, 3.0, 0.0, 0.0, true, 1)
                      transform = Geom;;Transformation.new(Geom;;Point3d.new(0.5,0.5,0))
                      cutgroup.transform! transform
                      
                      #intersections = cutgroup.entities.intersect_with true, cut_trans, basegroup.entities, base_trans , true, basegroup
                      
                      basegroup.explode
                      
                      dmp=cutgroup.explode;#erase the top and bottom of the letters
                      dmp.each{|f| f.erase! if f.is_a?(Sketchup;;Face) && f.normal.z.abs>0.5}
                      #add faces to 'holes' in the letters
                      dmp.each{|e| e.find_faces if e.is_a?(Sketchup;;Edge) && e.faces.length==1}
                      
                      model.active_view.zoom_extents
                      

                      Nothing is worthless, it can always be used as a bad example.

                      http://sdmitch.blogspot.com/

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

                      Advertisement