# Get curves from piping

**URL:** <https://forum.dynamobim.com/t/get-curves-from-piping/61867>\
**Category:** Revit\
**Tags:** python\
**Created:** [March 19, 2021, 10:23am UTC](https://forum.dynamobim.com/t/get-curves-from-piping/61867 "2021-03-19T10:23:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![theshysnail](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/theshysnail/32/146653_2.png) [@theshysnail](https://forum.dynamobim.com/u/theshysnail)\
**Post date:** [March 19, 2021, 10:23am UTC](https://forum.dynamobim.com/t/get-curves-from-piping/61867/1 "2021-03-19T10:23:27Z")

</div>

Hello all,

This problem is in continuation with an older question on the forum.

I want to get the curves from a piping network. It’s all working fine but whenever there are two or more fittings getting connected together, the output curve is unjoined.

Please have a look at this python script from the graph which joins the piping curves together.

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

pipes = []
fittings = []

for e in IN[0]:
	if e.GetParameterValueByName("Category") == IN[1]:
		pipes.append({
			"element": UnwrapElement(e),
			"location": e.GetLocation()
		})
	else:
		fittings.append({
			"element": UnwrapElement(e),
			"location": e.GetLocation()
		})

dist = []
for f in fittings:
	conections = f["element"].MEPModel.ConnectorManager.Connectors
	for c in conections:
		if c.IsConnected:
			for pc in c.AllRefs:
				for pipe in pipes:
					if pc.Owner.Id == pipe["element"].Id:
						startPoint = pipe["location"].StartPoint
						endPoint = pipe["location"].EndPoint
				
						distanceToStartPoint = f["location"].DistanceTo(startPoint)
						distanceToEndPoint = f["location"].DistanceTo(endPoint)
				
						if distanceToStartPoint > distanceToEndPoint:
							pipe["location"] = Line.ByStartPointEndPoint(startPoint, f["location"])
						else:
							pipe["location"] = Line.ByStartPointEndPoint(f["location"], endPoint)

OUT = [a["location"] for a in pipes]

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/5/053162e09028447af00fe2369738304c79d2c0bd.png)

> [@PolyCurve from a Pipe Network](https://forum.dynamobim.com/t/polycurve-from-a-pipe-network/48244):
>
> I am trying to get a polycurve from a pipe network in my Revit file. I could not find another way to get the centreline (as a polycurve) of this network other than following the below workflow. However, there are two problems with the workflow when: The piping is not drawn at one go i.e. continuous element IDs of pipes are not there in Dynamo workflow and a polycurve could not be formed. joinTolerance (for the gaps between two pipes due to pipe fitting) is greater than a (short) pip…

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [March 22, 2021, 8:59pm UTC](https://forum.dynamobim.com/t/get-curves-from-piping/61867/2 "2021-03-22T20:59:20Z")

</div>

Hello  
i don’t know the goal of your script but here is an alternative

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/3/3308521856a49bc0f58a2898f2742f5abefceee8.png)

```
import clr
import sys
import System
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

#import Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB

from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

toList = lambda x : x if hasattr(x, ' __iter__') else [x]
lstElemNetWork = toList(UnwrapElement(IN[0]))

lstDS_Geo = [] 
for e in lstElemNetWork:
	if isinstance(e.Location, LocationCurve):
		rvtCurve = e.Location.Curve
		lstDS_Geo.append(rvtCurve.ToProtoType())
	else:
		locPt = e.Location.Point
		connSet = e.MEPModel.ConnectorManager.Connectors
		lstConn = list(connSet)
		if connSet.Size == 2:
			try:
				pline = DB.PolyLine.Create(List[XYZ]([lstConn[0].Origin, locPt, lstConn[1].Origin]))
				lstDS_Geo.append(pline.ToProtoType())
			except:  
				# Unable to create Line. Points are likely coincident
				line = DB.Line.CreateBound(lstConn[0].Origin, lstConn[1].Origin)
				lstDS_Geo.append(line.ToProtoType())			
		else:
			for con in connSet:
				line = DB.Line.CreateBound(locPt, con.Origin)
				lstDS_Geo.append(line.ToProtoType())

OUT = lstDS_Geo
```

---

<div class="post-metadata">

**Author:** ![theshysnail](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/theshysnail/32/146653_2.png) [@theshysnail](https://forum.dynamobim.com/u/theshysnail)\
**Post date:** [March 23, 2021, 4:21am UTC](https://forum.dynamobim.com/t/get-curves-from-piping/61867/3 "2021-03-23T04:21:10Z")

</div>

Thanks a lot. The goal is just to get the total length of the piping network.
