Collect all model lines in a project using Python

Hi All,

Can somebody tell me a way of collecting all the model lines in a project using Python?

The code below collects all lines in project which I think includes detail lines? This is too slow on a large project that has got a bit messy.

import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#The inputs to this node will be stored as a list in the IN variables.

toggle = IN[0]
collector = []

if toggle == True:
collector.append(FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Lines).WhereElementIsNotElementType().ToElements())
else:
pass

#Assign your output to the OUT variable.
OUT = collector

Perhaps try to filter by type after gathering, or gather by type instead of category.

Hi @simon_murphy1,

Instead of calling the category, try calling OfClass(ModelLine).

Edit: Link to the class.

Edit 2.0:

Sorry, I was too fast with this. It seems not all classes in the API can be used to with the OfClass filter, where the ModelLine is one of these. Here the remark from the API:

Here’s an alternative way to recognize ModelLines from DetailLines using the CurveElementType property:

import clr

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

#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager

#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument

#---###Start scripting here:###---#
mc = FilteredElementCollector(doc).OfClass(CurveElement).ToElements()

OUT = []

for i in mc:
	ct = i.CurveElementType
	if ct == CurveElementType.ModelCurve:
		OUT.append(ct)
	else:
		OUT.append('This is a Detail Line')
5 Likes

I have previously done the following to find out how many detail/model lines are within a file and could be re purposed for what you want.

image

3 Likes

Maybe you could try using the 3D space as detail lines are never shown in the 3D space