Detect face on pushpull
-
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:
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!
-
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 isface.normal
.
Assuming the 'back side' of the 'wall' is parallel with the front side that contains 'face' then its normal with beface.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] - sopoint=rayt[0]
Now you knowpt
andpoint
... so to findthk
usethk=pt.distance(point)
and then use its -ve value inface.pushpull(-thk)
...You get a punched hole.
-
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.
-
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?
-
How did you add the face to pushpull ?
If it was withentities.add_face(p0,p1,p2,p3)
then simply useface=entities.add_face(p0,p1,p2,p3)
.
Then you have theface
andface.normal
is its normal vector, so reverse it to look behind the face with arayt=model.raytest(p0, face.normal.reverse)
andpoint=rayt[0]
is the hit point, and thenthk=p0.distance(point)
tells you how far you need to pushpull 'face
' [use-thk
value]......... -
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
-
@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 arayt=model.raytest(p0, face.normal.reverse)
andpoint=rayt[0]
is the hit point, and thenthk=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
-
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! -
My 2 cents: a (very) old script that creates holes with selected faces.
Watch your step: badly coded
-
Thanks Didier!
These examples are good for learning.
Regards,
Siegfried
Advertisement