Get curves from piping

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]

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

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
3 Likes

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