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

    Write all faces id's and point information to text file

    Scheduled Pinned Locked Moved Plugins
    13 Posts 3 Posters 740 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.
    • TIGT Offline
      TIG Moderator
      last edited by

      As all faces are oblong and 'flat' it's even easier...
      A face has a 'boundingbox'.
      bb=face.bounds
      A 'boundingbox' has various properties, including
      dX=bb.width dY=bb.height
      which would be the values you want.
      You either use 'selection' or all for collecting the faces - let's assume 'all'
      ` faces=[]
      Sketchup.active_model.active_entities.each{|e|faces << e if e.class==Sketchup::Face and e.normal.z.abs>0.9999}
      text="No,dX,dY\n"
      num="1"
      faces.each{|face|text << num+","+face.bounds.width.to_s+","+face.bounds.height.to_s+"\n"; num.next!}

      now write text to the file

      file=File.join(Sketchup.active_model.path, Sketchup.active_model.title+"_FaceDump.txt")
      fi=File.open(file, "w")
      fi.puts(text)
      fi.close`
      This should then find all flat faces and add their dX/dY values as a comma separated list, the ref 'num' is as 1,2,3...
      πŸ€“

      TIG

      1 Reply Last reply Reply Quote 0
      • N Offline
        neon_daytona
        last edited by

        Thanks for the quick reply.

        There is no selection of faces. All the faces have to be written out. So your code should work.

        dX and dY in my case are not the width and height of the face.
        Basically I need these 3 steps:

        1. Select a face.
        2. Select the extreme points for that face at its bottom. (Point 1 and Point 4 in the attached image)
        3. difference in coordinates for these 2 points is my dX and dY.

        Need to do this for all the faces in the model


        2.JPG

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

          Assuming your face is an orthogonal rectangle then the dX=bb.width and dY=bb.height [oddly the 'Z-height' in the SKP is called the 'bb.depth' !]

          Unfortunately your explanation is illogical.
          Points 1 and 4 are dX apart [without recourse to finding their coordinates at all!]

          If the face is not flat or orthogonal or a rectangle then the issue is more complex but still solvable...

          Please explain a little better...

          TIG

          1 Reply Last reply Reply Quote 0
          • N Offline
            neon_daytona
            last edited by

            @tig said:

            Assuming your face is an orthogonal rectangle then the dX=bb.width and dY=bb.height [oddly the 'Z-height' in the SKP is called the 'bb.depth' !]

            Unfortunately your explanation is illogical.
            Points 1 and 4 are dX apart [without recourse to finding their coordinates at all!]
            Points 1 and 4 are definitely dX apart but may not be in the same Y coordiante.
            If the face is not flat or orthogonal or a rectangle then the issue is more complex but still solvable...
            As I mentioned in my first post, the face can be of any shape.
            Please explain a little better...

            I guess this new image will clear the question. Sorry for the confusion.
            There are 2 faces in the XY plane in the image. The first face on the left, I need dX and dY between point 1 and 4. In the second face on the right, I need dX and dY between points 1 and 6. The faces can be of any shape and have as many edges as possible.
            But the common thing is that all faces are in XY plane. So I need to find the edge/line that is at the bottom of the face and pick the 2 points attached to line to get the dX and dY.


            3.JPG

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

              A question along similar lines:
              I am trying to write the input data to a file named like the rb file and in the same directory as the rb file. This will provide users with their on default data not what the author picked. Currently in windows the file is written to the desktop and I have not found code to change it. Where I would like it is in .....plugins\K2WS.

              Keith

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

                Shashi

                That's much clearer...
                The faces are 'flat' in the Z-plane BUT can any number of vertices and you need to find the length of the edge that has a vertex that has the minimum Y value, since every vertex will have two faces the edge required is the one where its other vertex also has the minimum Y value.
                One scenario not covered is what if the minimum Y vertex has two edges that both have other vertices that have the same Y - I assume we take the one with the lesser X ?
                Here's some code

                faces=[]
                Sketchup.active_model.active_entities.each{|e|faces << e if e.class==Sketchup;;Face and e.normal.z.abs>0.9999}
                ### == 'flat'
                num="1"
                text="No,dX,dY\n"
                faces.each{|face|
                  pts=[]
                  verts=face.vertices
                  verts.each{|v|pts << v.position}
                  pt=pts[0].clone
                  minY=pt.y
                  minX=pt.x
                  pts.each{|p|
                    if p.y < minY
                      pt=p.clone
                      minY=pt.y
                      minX=pt.x
                    end
                  }
                  ### pt is at minY vertex
                  ve=verts[0]
                  verts.each{|v|ve=v if v.position==pt}
                  ### ve is minY vertex
                  edges=ve.edges
                  edges.each{|e|edges.delete(e) if not face.edges.include?(e)}
                  ### 'edges' is just the face's 2 edges with 'minY'
                  edge=edges[0]
                  ey=edge.other_vertex(ve).position.y
                  nedges=[]
                  edges.each{|e|
                    if e.other_vertex(ve).position.y <= ey
                      nedges << e
                    end
                  }
                  if not nedges[1]
                    nedge=nedges[0]
                  else
                    n0=nedges[0]
                    n1=nedges[1]
                    if n0.other_vertex(ve).position.x <= n1.other_vertex(ve).position.x
                      nedge=n0
                    else
                      nedge=n1
                    end
                  end
                  ### 'nedge' is the required edge
                  ps=nedge.start.position
                  pe=nedge.end.position
                  dX=(ps.x-pe.x).abs.to_s
                  dY=(ps.y-pe.y).abs.to_s
                  ###
                  ### now add data to 'text'
                  text << num+","+dX+","+dY+"\n"
                  ###
                  num.next!
                  ### '1' >> '2' etc
                }
                ### now write the completed 'text' to a file
                file=File.join(Sketchup.active_model.path, Sketchup.active_model.title+"_FaceDump.txt")
                fi=File.open(file, "w")
                fi.puts(text)
                fi.close
                ### done!
                

                this is untested - please try and report back...

                TIG

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

                  Keith

                  Your separate question.... πŸ˜‰

                  The .rb file's details are got from the special __FILE__ variable which returns the full path the the .rb file.
                  So let's assume that the Ruby file is called ' keith.rb'...
                  Then
                  rb=__FILE__ >>> 'C:\Program Files\Google\Google SketchUp 7\Plugins\K2WS\keith.rb'
                  To find its folder use
                  folder=File.dirname(rb) >>> 'C:\Program Files\Google\Google SketchUp 7\Plugins\K2WS'
                  To find its name use
                  name=File.basename(rb,".*") >>> 'keith'
                  To compile the path to the new matching .txt file use
                  txtfile=File.join(folder, name+".txt") >>> 'C:\Program Files\Google\Google SketchUp 7\Plugins\K2WS\keith.txt'

                  NOTE: another 'one-step' way [but somewhat less clear] would be this
                  txtfile=__FILE__.gsub(/.rb$/,'.txt')
                  Which directly returns 'C:\Program Files\Google\Google SketchUp 7\Plugins\K2WS\keith.txt' without any intermediate steps...

                  I show the File parsing/join methods because they do have wider uses...

                  Remember that ' txtfile' is only a string representing the file path and you need to use the File.open... etc to make the file and write to it... See the example[s] in the post[s] below...
                  πŸ€“

                  TIG

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

                    Thanks TIG That should help me out. I had already worked out the file new/open etc. but found no help on directories etc.

                    Keith

                    1 Reply Last reply Reply Quote 0
                    • N Offline
                      neon_daytona
                      last edited by

                      Thanks TIG for the help.
                      There was one small typo, which I edited.
                      The text file is always saved to πŸ˜„ directory not in the active model path.
                      Need to verify that, But the main functionality works like a charm.

                      Trying it on bigger models and will then update back.

                      Thanks Again

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

                        Shashi

                        Glad to hear it helped...
                        I hadn't tested the code as I typed it 'cold', from memory as one stream of consciousness - can you tell me were my 'typo is' - I can then edit the original code-block so that anyone else trying to use it doesn't have to fret about sorting that out... Saving the data file with the model OR to a fixed file-path is your choice - so if that's the 'typo' then I need not worry... as I just needed a 'FaceDump.txt' file to write to... πŸ˜‰

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • N Offline
                          neon_daytona
                          last edited by

                          TIG,

                          this is the typo

                          minX=py.x
                          needs to be changed to
                          minX=pt.x

                          Thanks

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

                            Thanks! fixed it... πŸ€“

                            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