• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Detect face on pushpull

Scheduled Pinned Locked Moved Developers' Forum
10 Posts 4 Posters 448 Views 4 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.
  • B Offline
    BWV
    last edited by 25 Jan 2011, 15:53

    Hello,

    I'm completely new to SkechUp scripting, but have found it impressive so far. I can't see why haven't I touched it after years of SketchUp use.

    One thing that I have been wondering is about "detecting" a face during pushpull right on the script. Similar to step 5 in the following:

    Screen shot 2011-01-25 at 13.42.46.png

    I'm almost sure it's not a viable solution, then I'd like to ask: what's a recommended procedure to achieve the same result, taking into consideration that the amount (length) of pushpull is unknown? Maybe creating a long edge or face and intersecting to then calculate the correct measure?

    Thanks!

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 25 Jan 2011, 16:18

      If you know the 'wall' thickness [thk] that's what you pushpull [-ve]... you might have it from the earlier step when making the rectangle on the ground that was used to pushpull the 'wall'...
      In step 4 you know the face, that you will use with
      face.pushpull(-thk)

      BUT let's assume you don't know the wall's thickness...
      The yet-to-be-pushpulled face's normal is face.normal.
      Assuming the 'back side' of the 'wall' is parallel with the front side that contains 'face' then its normal with be face.normal.reverse. You can therefore find that face...
      OR...
      You can find this back-face by using a raytest
      rayt=model.raytest(pt, face.normal.reverse)
      Where ' pt' is one of the points you used to make 'face' you will be pushpulling...
      The returned array ' rayt' contains the point that is first hit and what was hit [back-face] - so point=rayt[0]
      Now you know pt and point... so to find thk use thk=pt.distance(point) and then use its -ve value in face.pushpull(-thk)...

      You get a punched hole. πŸ€“

      TIG

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 25 Jan 2011, 16:23

        My understanding is that you want to detect how far to push/pull the inner face so it hits the back face perfectly, right? If so, then I would find 2 things - a vertex from the face you are going to pushpull, and find the face you are trying to push/pull to. Then you can use the method .distance_to_plane to find the distance from your vertex to the plane of the face.

        http://code.google.com/apis/sketchup/docs/ourdoc/point3d.html#distance_to_plane

        distance_to_pushpull = vertex.position.distance_to( backface.plane )

        That should work, as long as you can determine what face you are trying to pushpull to.

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • B Offline
          BWV
          last edited by 25 Jan 2011, 16:33

          Thanks TIG and Chris,

          @chris fullmer said:

          That should work, as long as you can determine what face you are trying to pushpull to.

          Exactly, that's the question.

          TIG's suggestions were very clever and I have been trying to understand correctly, unfortunately looks like the normal solution is not what I need. Once I have the that face normal, is it possible to find the face itself?

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 25 Jan 2011, 16:38

            How did you add the face to pushpull ?
            If it was with entities.add_face(p0,p1,p2,p3) then simply use face=entities.add_face(p0,p1,p2,p3).
            Then you have the face and face.normal is its normal vector, so reverse it to look behind the face with a rayt=model.raytest(p0, face.normal.reverse) and point=rayt[0] is the hit point, and then thk=p0.distance(point) tells you how far you need to pushpull ' face' [use -thk value].........

            TIG

            1 Reply Last reply Reply Quote 0
            • C Offline
              Chris Fullmer
              last edited by 25 Jan 2011, 16:39

              Yes, you could use your face, then do my_face.all_selected to get an array of all elements (faces and edges) that are connected to your face. Then sort through that and get just the faces. Then compare all their normals to your face's normal. The parallel planes will have the same normal. So in your example, you should an array of three face - your face, the face that surrounds it, and the backface. Then you would determine that your face is not the back face, and any face that lies on the same plane as your face is not the back face. That would be one theory on how to determine which face is the backface.

              Chris

              Lately you've been tan, suspicious for the winter.
              All my Plugins I've written

              1 Reply Last reply Reply Quote 0
              • B Offline
                BWV
                last edited by 25 Jan 2011, 16:50

                @tig said:

                simply use face=entities.add_face(p0,p1,p2,p3).
                […] face.normal is its normal vector, so reverse it to look behind the face with a rayt=model.raytest(p0, face.normal.reverse) and point=rayt[0] is the hit point, and then thk=p0.distance(point) tells you how far you need to pushpull ' face'

                You probably feel like "why I'm writing this twice?" πŸ˜„
                But the fact is that now I got it. Sorry, there is a lot I need to learn, I really appreciate your help.

                @chris fullmer said:

                Yes, you could use your face, then do my_face.all_selected to get an array of all elements (faces and edges) that are connected to your face.

                Chris, nice solution! In my real application for the script though this may not work, not always everything is connected. But it will solve another problem I had earlier.

                Thanks a lot TIG and Chris,

                Best wishes,

                Siegfried

                Edit: fixed a typo

                1 Reply Last reply Reply Quote 0
                • T Offline
                  TIG Moderator
                  last edited by 25 Jan 2011, 16:53

                  It's OK... I have considerable patience and I 'suffer fools gladly', as I am often one!
                  If you don''t know the answer you'll never find it out by NOT asking! πŸ˜„

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    Didier Bur
                    last edited by 25 Jan 2011, 20:25

                    My 2 cents: a (very) old script that creates holes with selected faces.
                    Watch your step: badly coded 😳


                    opener.zip

                    DB

                    1 Reply Last reply Reply Quote 0
                    • B Offline
                      BWV
                      last edited by 26 Jan 2011, 12:14

                      Thanks Didier!

                      These examples are good for learning.

                      Regards,

                      Siegfried

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      1 / 1
                      • First post
                        6/10
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement