Getting coordinates and distances between two element

Hi everyone, I want some help on my project.
Currently I am trying to get the distances between two elements. So far, I managed to get the selected element from a link file (which are two beams). Then I manage to generate out two beams with two coordinate locations and the line of the beam. However, I am struggling to find the distance between two of these beams, can I get some help plz.

Hi @michael-x.shum,
How exactly do you want to check the distance between two beams? Is it enough for you if it would be from the center point of one beam to the center point of another beam? If yes, then you can get the midpoint of the line (you can obtain this with the node ‘Element.GetLocation’) and then compare these two points with the node ‘Geometry.DistanceTo’.

Yeah, you basically have it. It just depends on if you have any specifics around which points you’re calculating from. You can get the midpoint of the centerlines or you can use Point.ClosestTo() to get the shortest distance between elements. Either way, you just need to specify the two geometries to measure between.

thanks guys, is there any way to specify the location points on the outline of the beam? then calculate the distance?

Again, it depends on exactly what you want, but, yes, it’s possible. Using Geometry.ClosestPoint should get you pretty close if not all the way there with the beam solids. Otherwise you can always get your nearest points and then project that onto the beam geometry as a polysurface. In some cases, this may not be the most direct distance between elements, but it should be pretty accurate most of the time.