Using Python, is there a way to look up all objects (shells/faces/edges/vertices) in a body that intersect with a particular point in 3D space?
For example, imagine my body is a cube occupying [0, 1]x[0, 1]x[0, 1]. Given the point (0, 0, 0.5), I'd like to get the Python edge from (0, 0, 0) to (0, 0, 1). Given the point (0, 0.5, 0.5), I'd like to get the face on the YZplane in Python.
Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
Re: Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
Code: Select all
doc = App.ActiveDocument
box = doc.addObject("Part::Box", "Box")
doc.recompute()
point = App.Vector(5, 0, 5)
distance, points, info = box.Shape.distToShape(Part.Vertex(point))
print(info)
Re: Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
What is the structure of info?
Re: Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
Code: Select all
[('Face', 2, (5.0, 5.0), 'Vertex', 0, None)]:
'Face' = subelement
2 = index of subelement (zerobased)
(5.0, 5.0) = (u, v) parameters of the point.
Re: Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
Fantastic. Thank you!
Re: Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
How do I evaluate the subelement at the supplied parameters?

 Veteran
 Posts: 1358
 Joined: Thu Sep 24, 2020 10:31 pm
 Location: Hawaii
 Contact:
Re: Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
Code: Select all
face = box.Shape.Faces[2]
print(face.valueAt(5,5)) #> Vector (5.0, 0.0, 5.0)
face.Surface.normal(5,5)# normal at location etc.
Re: Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
How do I transform the result of valueAt into a correct 3D point? I'm trying to use it to produce a point cloud of a BREP, but it is giving incorrect results.
Re: Get all Shells/Faces/Edges/Vertices at a particular point in 3D space
valeAt is returning a Vector() and usually a Vector() will suffice to feed many methods that uses "3d Points" like lines and other entities. In other word where you have to use the returned info?
Regards
Carlo D.
My English and Italian Scripting Guide https://github.com/onekk/freecaddoc.
My Blog: https://onekkmaker.blogspot.com/
To help development see on GitHub Page
For enquiry about customized FC Scripting job PM me.
My Blog: https://onekkmaker.blogspot.com/
To help development see on GitHub Page
For enquiry about customized FC Scripting job PM me.