sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Intersection - Problem with coplanar cuts

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 365 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.
    • C Offline
      CAUL
      last edited by

      I'm trying to put together a robust cut script but it turns out to be quite difficult. The attached .skp shows a problem with coplanar cuts that my script is unable to handle.

      As seen in the .skp, it is possible to accomplish a proper cut manually with the following steps:

      1. Intersect the groups
      2. Make a group of the intersection edges (2 copies)
      3. Explode the intersection edges into both groups separately
      4. Merge the groups

      However, I can't manage to perform these steps in a script (see Script Cut scene in the .skp). The problem is in step 3. The UI intersect method produces the face/face cuts as well as coplanar cuts. The API intersect_with gives only edges for face/face cuts. The script tries to get around this by adding all edges from group 1 to group 2, it then merges the geometry and finally deletes the stray edges. This doesn't work though, the problem is that the geometry just doesn't merge (it's probably too complex or something..)

      So, is there a (non-O(n^2)) way to get the same set of edges through the API as you get with the UI version of intersect, ie, a group of edges that includes coplanar cuts?


      How do you properly intersect these groups in a script?


      IntersectFail.skp

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        Have you tried Edge# find_faces on the collection of intersect edges.

        @unknownuser said:

        Edge.find_faces

        The find_faces method is used to create all of the Faces that can be created with this edge. For example, if you use the API to draw three edges that form a triangle, the face between them will not show up because you've only drawn the edges, but if you call find_faces on one of the edges, the triangle will be filled in.

        iedges.each {|e| e.find_faces }
        

        โ“

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          The .intersect_with() method returns an array of the 'resultant edges', so as Dan says you could use
          iedges = some_entities.intersect_with(.......)
          and then
          iedges.each{|e| e.find_faces }
          In which entities context are you putting the 'resultant edges' ?

          Alternatively you could put the 'resultant edges' into a temporary group within the desired context, and then explode that group - the act of exploding it ought to auto-merge the edges/faces ?

          TIG

          1 Reply Last reply Reply Quote 0
          • C Offline
            CAUL
            last edited by

            Thanks for the replies. I think my original post was a bit unclear, the problem is quite subtle and it isn't a problem with intersect generally but rather:

            1. Explode doesn't always merge geometry properly. In the image below an explosion will fail to cut the top face in the left model. The grouped edges in the right model is a subset, and in this case an explosion will split the top face into four faces as we expect. So, for explosion to be robust the geometry needs to be as simple as possible.

            2. Intersect_with doesn't provide all edges for coplanar cuts.

            The original problem was a combination of 1 and 2.

            If the two groups are cut from the UI, the resulting edges represents all coplanar cuts. So, what's the difference between the UI intersect and the API intersect? It turns out that the resultant edges from UI intersect is (conceptually):

            intersect_with g0, g1 + intersect_with g1, g0

            Thus, the solution is to make two calls to intersect_with in the API. The script below properly cuts the two pipes.

            ` def mergeGroups(ent, g0, g1)
            ng = ent.add_group
            ng.entities.add_instance(g0.entities.parent, g0.transformation)
            ng.entities.add_instance(g1.entities.parent, g1.transformation)
            g0.erase!
            g1.erase!
            nt1 = ng.entities[0]
            nt2 = ng.entities[1]
            nt1.explode
            nt2.explode
            return ng
            end

            def intersect(ent, g0, g1)
            eg = ent.add_group
            g0.entities.intersect_with false, g0.transformation, eg , g1.transformation , true, g1
            return eg
            end

            def cutGroupPair(ent, g0, g1)

            ge0 = intersect(ent, g0, g1)
            ge0.transform! g1.transformation

            ge1 = intersect(ent, g1, g0)
            ge1.transform! g0.transformation

            g00 = mergeGroups(ent, ge0, g0)
            g11 = mergeGroups(ent, ge1, g1)

            ng = mergeGroups(ent, g11, g00)

            return ng

            end

            mod = Sketchup.active_model
            ent = mod.entities
            sel = mod.selection

            cutGroupPair(ent, sel[0], sel[1])`


            Cuts.jpg

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              You could try the first argument (recurse) of .intersect_with() method set as 'true'.
              Also you can include more than one 'entity' in the method's final argument (entities2) - passed as an array of entities...
              Say [g1, g2] or even [g1.entities.to_a, g2.entities.to_a].flatten ๐Ÿ˜•

              TIG

              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