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

    [Resolved] How select a face created in another face?

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 5 Posters 344 Views 5 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
      LSeibt
      last edited by LSeibt

      Hello everyone

      I am developing a plugin to make holes in a given geometry.
      Select the face where I will apply this geometry and design lines that will make this hole.
      How do via code, to capture that face created as a result of this new geometry that was drawn on the selected face?

      Thanks

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


        ` set1 = Sketchup.active_model.entities.to_a

        create new geometry

        set2 = Sketchup.active_model.entities.to_a

        subtract set1 from set2

        setnew = set2 - set1
        facenew=false
        setnew.each {|e| facenew=e if e.class==(Sketchup::Face) }`


        That is a very simple example, it may be more complex if the face your 'carving' is within a Group or ComponentInstance.

        I'm not here much anymore.

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

          @dan rathbun said:

          facenew=false setnew.each {|e| facenew=e if e.class==(Sketchup::Face) }

          what about:

          facenew = setnew.select{|e| e.is_a?(Sketchup::Face)}
          ❓

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

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

            @thomthom said:

            what about:

            facenew = setnew.select{|e| e.is_a?(Sketchup::Face)}

            Yes, but facenew WILL be an array, with possible more than 1 face.

            The original poster would need to check .areaof each item in array, to determine which face was smaller and delete it.

            I'm not here much anymore.

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

              You know the 'face' that will contain the new face - since you said you selected it.
              Since you are creating new geometry you will know the 'edges' you have just added to the entities.
              If you make a circle it returns the edges as an array. If the hole is some other shape you will be adding these so you can get references to them?
              Any one of these new edges (e.g. edges[0]) should have two faces - the one that is NOT 'face' is the 'new face' ?
              If there's a chance the new face won't be wholly on 'face' then if an inspected 'edge' doesn't include 'face' in its 'faces' then try processing more like this...

              ### assume the selected face is called 'face'
              ### and new edges you've added are in an array called 'edges'
              newface=nil
              0.upto(edges.length-1).each{|i|
                if edges[i].faces.include?(face)
                  if edges[i].faces[1]
                    edges[i].faces.each{|f|
                      if f != face
                        newface = f
                        break
                      end
                    }
                  end
                else
                  next
                end
              }
              ### 'newface' is the new face or 'nil' if it's not on 'face' at all
              ### you can then find the new 'separate' face if desired...
              newface = edges[0].faces[0] if not newface
              ### 'newface' is found at last even if not on 'face' at all !
              ### alternatively 'not newface' tells you it's missed face all together...
              
              

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                todd burch
                last edited by

                If you are using entities.add_face, the new face created is returned as the result. You can create the face with either lines (edges) or points. No big deal.

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

                  @unknownuser said:

                  If you are using entities.add_face, the new face created is returned as the result. You can create the face with either lines (edges) or points. No big deal.

                  Yes .. You're right.
                  This morning I could get tested and worked properly in this way.
                  Thanks

                  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