Auto Dimension for Fabrication Part from grid

Hello Everyone,
I am trying to write a script to select fabrication element (duct and pipe), extract their edges for duct and centerline for pipe, then select grid as reference and by “Dimension.byelements” place the dimension.

Because the Fabrication part are mesh, I tried to extract the edge point and make it as a curve but it didn’t work.

I appreciated if you could take look.

Dimension for fab part.dyn (45.5 KB) image