sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Add_face(edearray) not working?

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 3 Posters 505 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.
    • T Offline
      tafkab76
      last edited by

      In the Ruby API it says that youn can create a face by passing an array of edges as an argument:

      @unknownuser said:

      Entities.add_faceSketchUp 6.0+
      The add_face method is used to create a face. You can call this method a number of ways:

      entities.add_face(edge1, edge2, edge3, ...)
      entities.add_face(edgearray)
      entities.add_face(pt1, pt2, pt3, ...)
      entities.add_face([pt1, pt2, pt3,...])
      entities.add_face(curve)

      I tried it like this

      punkteArray = []
      edgeArray =[]
      
      punkteArray.push(Geom;;Point3d.new(0,0,0))
      punkteArray.push(Geom;;Point3d.new(100,0,0))
      punkteArray.push(Geom;;Point3d.new(100,0,100))
      punkteArray.push(Geom;;Point3d.new(0,0,100))
      punkteArray.push(Geom;;Point3d.new(0,0,0))
      
      edgeArray = ents.add_edges punkteArray
      
      face = ents.add_face(edgeArray)
      

      but that returned nil and no edges were drawn at all. I know that I could have used

      face = ent.add_face(punkteArray)
      

      but I was hoping to be able to create a face with a hole in it by passing an array with the outer and inner loop edegs to the add_face method, but not even passing a single loops seems to work.

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

        add_face( edges ) does work. I've used it lots of times. Even your sample code works.

        add_face_edges.png

        But...

        @tafkab76 said:

        but I was hoping to be able to create a face with a hole in it by passing an array with the outer and inner loop edegs to the add_face method, but not even passing a single loops seems to work.

        You cannot create with a hole in one go. Create the face first - without outer loop. Then take your inner loops and create faces for each of them - you then erase the face created with the inner loops.

        Btw - ents does that refer to model.active_entities ? Or did you use model.entities ?

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

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

          😲

          I didn't notice the add_face command at the end (it was below the code fold) But I'm seeing the same thing. I don't understand what's going on there... 😕

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

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

            But I can´t see the face on your screen, only four edges?

            Here ist what it looks like when I execute the code on my machine. Maybe it´s a difference, because I use Ruby Code Editor?

            [xxl-img:xg9qtt3f]http://www.steffenblome.de/add_face.jpg[/xxl-img:xg9qtt3f]

            as you can see I used

            ent = mod.entities
            

            but I just tried

            ent = mod.active_entities
            

            with the same results.

            And thanks for that advice on how to create a face with a hole, I´m going to use that.

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

              Ah!

              When you created a set of edges with add_edges it didn't merge the start and end vertex.

              EdgeLoop.png

              That prevented it from creating the face because it wasn't a closed loop.

              When I created a set of edges separately which where merged it did work.

              So the failure of add_face is a result of add_edges not merging crossing vertices.

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

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

                Ok, I see. That also explains why find_faces didn´t work on neither of the edges.
                So add_face(edgearray) doesn´t work on API created egdes? Or is there a command that forces edges to merge to loops if possible?

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

                  @tafkab76 said:

                  So add_face(edgearray) doesn´t work on API created egdes?

                  It works if the edges are a closed loop.
                  I think if you create each face individually with add_edge it will work. Alternatively you can try to intersect the created edges with themselves.

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

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

                    But - in your case where you say:

                    @tafkab76 said:

                    but I was hoping to be able to create a face with a hole in it by passing an array with the outer and inner loop edegs to the add_face method, but not even passing a single loops seems to work.

                    You cannot create a face with holes in one operation.

                    @thomthom said:

                    You cannot create with a hole in one go. Create the face first - with the outer loop points. Then take your inner loop points and create faces for each of them - you then erase the face created with the inner loops.

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

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

                      Yes, I got that.

                      Thx!

                      1 Reply Last reply Reply Quote 0
                      • K Offline
                        krouza
                        last edited by

                        @tafkab76 said:

                        Yes, I got that.

                        Thx!

                        You must use selection like this:

                        <span class="syntaxdefault">selection&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection<br />status&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add&nbsp;edges<br />&nbsp;&nbsp;<br /></span><span class="syntaxcomment">#&nbsp;Get&nbsp;an&nbsp;Array&nbsp;of&nbsp;all&nbsp;of&nbsp;the&nbsp;selected&nbsp;Edges<br /></span><span class="syntaxdefault">edges&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">find_all&nbsp;</span><span class="syntaxkeyword">{&nbsp;|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|&nbsp;</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">kind_of</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Edge</span><span class="syntaxkeyword">)}<br />&nbsp;&nbsp;&nbsp;<br /></span><span class="syntaxcomment">#&nbsp;Try&nbsp;to&nbsp;create&nbsp;a&nbsp;Face&nbsp;from&nbsp;the&nbsp;Edges&nbsp;in&nbsp;the&nbsp;active&nbsp;component<br /></span><span class="syntaxdefault">face&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">nil<br />begin<br />&nbsp;&nbsp;&nbsp;&nbsp;face&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_face&nbsp;edges<br />rescue<br />end</span>
                        
                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          You can get a type of entity faster by using grep. (See this thread: http://sketchucation.com/forums/viewtopic.php?f=180&t=48885 )

                          <span class="syntaxdefault"></span><span class="syntaxcomment">#&nbsp;Get&nbsp;an&nbsp;Array&nbsp;of&nbsp;all&nbsp;of&nbsp;the&nbsp;selected&nbsp;Edges<br /></span><span class="syntaxdefault">edges&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">grep</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Edge</span><span class="syntaxkeyword">)&nbsp;</span><span class="syntaxdefault"></span>
                          

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

                          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