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

    Is an entity in a surface

    Scheduled Pinned Locked Moved Developers' Forum
    13 Posts 6 Posters 1.4k Views 6 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.
    • thomthomT Offline
      thomthom
      last edited by

      <span class="syntaxdefault">def&nbsp;get_surface</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">face&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;</span><span class="syntaxdefault">surface&nbsp;</span><span class="syntaxkeyword">=&nbsp;{}&nbsp;</span><span class="syntaxcomment">#&nbsp;Use&nbsp;hash&nbsp;for&nbsp;speedy&nbsp;lookup<br />&nbsp;&nbsp;</span><span class="syntaxdefault">stack&nbsp;</span><span class="syntaxkeyword">=&nbsp;[&nbsp;</span><span class="syntaxdefault">face&nbsp;</span><span class="syntaxkeyword">]<br />&nbsp;&nbsp;</span><span class="syntaxdefault">until&nbsp;stack</span><span class="syntaxkeyword">.empty?<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">face&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">stack</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">shift<br />&nbsp;&nbsp;&nbsp;&nbsp;edges&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select&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">soft</span><span class="syntaxkeyword">?&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;</span><span class="syntaxdefault">edge&nbsp;in&nbsp;edges<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">for&nbsp;</span><span class="syntaxdefault">face&nbsp;in&nbsp;edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">faces<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next&nbsp;</span><span class="syntaxkeyword">if&nbsp;</span><span class="syntaxdefault">surface</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">key</span><span class="syntaxkeyword">?(&nbsp;</span><span class="syntaxdefault">face&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">stack&nbsp;</span><span class="syntaxkeyword"><<&nbsp;</span><span class="syntaxdefault">face<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;surface</span><span class="syntaxkeyword">[&nbsp;</span><span class="syntaxdefault">face&nbsp;</span><span class="syntaxkeyword">]&nbsp;=&nbsp;</span><span class="syntaxdefault">face<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end<br />&nbsp;&nbsp;&nbsp;&nbsp;end<br />&nbsp;&nbsp;end<br />&nbsp;&nbsp;surface</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">keys<br />end<br /></span>
      

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

      1 Reply Last reply Reply Quote 0
      • Al HartA Offline
        Al Hart
        last edited by

        Thanks ThomThom,

        I'll give these a try.

        Al Hart

        http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
        IRender nXt from Render Plus

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          hi,
          this seems to be an interesting approach, but
          what is returned by the method?

          is it an array of elements, i can iterate?
          i am not yet familiar with "keys" etc..... -:)

          if this gives back all entities of the "surface", how could i iterate thru it?
          when i try, i get errors,
          thanx
          stan

          @thomthom said:

          <span class="syntaxdefault">def get_surface</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> face </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">  surface </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{}</span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Use hash for speedy lookup<br /></span><span class="syntaxdefault">  stack </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[</span><span class="syntaxdefault"> face </span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">  until stack</span><span class="syntaxkeyword">.empty?<br /></span><span class="syntaxdefault">    face </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> stack</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">shift<br />    edges </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> face</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">edges</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">select </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">|</span><span class="syntaxdefault"> e</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">soft</span><span class="syntaxkeyword">?</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">    for edge in edges<br />      for face in edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">faces<br />        next if surface</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">key</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> face </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">        stack </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> face<br />        surface</span><span class="syntaxkeyword">[</span><span class="syntaxdefault"> face </span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> face<br />      end<br />    end<br />  end<br />  surface</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">keys<br />end<br /></span>
          
          1 Reply Last reply Reply Quote 0
          • S Offline
            slbaumgartner
            last edited by

            The return is an Array of all the Faces from any surface containing the Face passed as the argument. If the Face is not in a surface, the return will be an empty array.

            1 Reply Last reply Reply Quote 0
            • artmusicstudioA Offline
              artmusicstudio
              last edited by

              @slbaumgartner said:

              The return is an Array of all the Faces from any surface containing the Face passed as the argument. If the Face is not in a surface, the return will be an empty array.

              hello,
              thanx a lot. yes,

              in the mean time i renamed the array to @surface.keys and got the array back. works perfectly.

              i have to find out, if there is a way to return this array without renaming (return xxxx ???)

              stan

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

                Where did you get @surface from?

                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

                  @artmusicstudio said:

                  i am not yet familiar with " keys" etc..... -:)

                  Go to the Ruby Resources "Sticky Thread" here:
                  RUBY PROGRAMMING REFERENCES

                  Get the CHM files for whatever version Ruby your SketchUp is using.
                  SketchUp v8, 2013 and earlier uses Ruby 1.8.6
                  (some earlier version used Ruby 1.8.5 and 1.8.0, FYI)

                  THEN ... lookup the Hash#keys() method

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • artmusicstudioA Offline
                    artmusicstudio
                    last edited by

                    @thomthom said:

                    Where did you get @surface from?

                    hi thomthom,

                    the method is

                    having a smooth mesh with any loops projected on it and intesect

                    selection of one or more surfaces by user and calling the method

                    iterating thru selected surfaces

                    iteration thru all elements within one of them

                    further operation with edges within the surface, especially the smooth ones

                    this peace of code for surface works super for me.

                    stan

                    1 Reply Last reply Reply Quote 0
                    • artmusicstudioA Offline
                      artmusicstudio
                      last edited by

                      @dan rathbun said:

                      @artmusicstudio said:

                      i am not yet familiar with " keys" etc..... -:)

                      Go to the Ruby Resources "Sticky Thread" here:
                      RUBY PROGRAMMING REFERENCES

                      Get the CHM files for whatever version Ruby your SketchUp is using.
                      SketchUp v8, 2013 and earlier uses Ruby 1.8.6
                      (some earlier version used Ruby 1.8.5 and 1.8.0, FYI)

                      THEN ... lookup the Hash#keys() method

                      hi dan, thanx,
                      next one to be studied (of still so many....). -:)

                      just to be sure of universality (ruby-versions), i run the code always in 2014 and v8 in win7, vista and xp....
                      stan

                      1 Reply Last reply Reply Quote 0
                      • S Offline
                        slbaumgartner
                        last edited by

                        TT's snippet earlier in this post contains a couple of bugs: it will raise an exception if the
                        argument isn't a Face (or something that supports #edges), and it will find false surfaces
                        built where more than two Faces meet at a soft Edge. The below fixes these issues.

                        
                        def get_surface( face )
                          return [] unless face.is_a?(Sketchup;;Face)
                          surface = {} # Use hash for speedy lookup
                          stack = [ face ]
                          until stack.empty?
                            face = stack.shift
                            edges = face.edges.select { |e| e.soft? && e.faces.length == 2}
                            for edge in edges
                              for face in edge.faces
                                next if surface.key?( face )
                                stack << face
                                surface[ face ] = face
                              end
                            end
                          end
                          surface.keys
                        end
                        
                        
                        1 Reply Last reply Reply Quote 0
                        • tt_suT Offline
                          tt_su
                          last edited by

                          That's for that revised version! 😄

                          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