sketchucation logo sketchucation
    • Login
    1. Home
    2. lovebob
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    L
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 4
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Cleaning up after intersect_with

      @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.

      posted in Developers' Forum
      L
      lovebob
    • RE: Cleaning up after intersect_with

      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!

      posted in Developers' Forum
      L
      lovebob
    • RE: Cleaning up after intersect_with

      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.

      posted in Developers' Forum
      L
      lovebob
    • Cleaning up after intersect_with

      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
      
      
      posted in Developers' Forum
      L
      lovebob
    • 1 / 1