Clash Detection Using Python

Hello,
i am new to python and trying to create python script for clash detection and found some codes on forums and tried it but output is empty even it has clash. Can someone help me what i’m doing Wrong.

     Version:0.9 StartHTML:00000097 EndHTML:00004880 StartFragment:00000199 EndFragment:00004842 # Enable Python support and load DesignScript library
    import clr
    clr.AddReference('ProtoGeometry')
    from Autodesk.DesignScript.Geometry import *

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

    clr.AddReference('RevitAPIUI')
    from Autodesk.Revit.UI import *

    clr.AddReference('System')
    import System
    from System.Collections.Generic import *

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

    clr.AddReference('RevitServices')
    import RevitServices
    from RevitServices.Persistence import DocumentManager
    from RevitServices.Transactions import TransactionManager

    # The inputs to this node will be stored as a list in the IN variables.
    cate1 = UnwrapElement(IN[0])
    cate2 = UnwrapElement(IN[1])

    # Place your code below this line
    doc = DocumentManager.Instance.CurrentDBDocument

    catid1 = int(str(cate1.Id))
    catid2 = int(str(cate2.Id))

    coll = FilteredElementCollector(doc)
    bic = System.Enum.ToObject(BuiltInCategory,catid1)
    coll.OfCategory(bic).WhereElementIsNotElementType()

    coll2 = FilteredElementCollector(doc)
    bic2 = System.Enum.ToObject(BuiltInCategory,catid2)
    coll2.OfCategory(bic2).WhereElementIsNotElementType()

    for i in coll2:
    clash =coll.WherePasses(ElementIntersectsElementFilter(i))

    # Assign your output to the OUT variable.
    OUT = coll,coll2,clash

Try adding:

coll.OfCategory(bic).WhereElementIsNotElementType().ToElements()

coll2.OfCategory(bic2).WhereElementIsNotElementType().ToElements()


try this topic.

Hi,
thanks for reply, I tried adding .ToElements() still the result is same.

Hi,
Thanks for reply, I tried your script. It shows an error at line 79 AttributeError: ‘LocationPoint’ object has no attribute ‘Curve’

ah that is because it is clashes with some point element in your link file. what is the final output you wanna achieve?

It is empty because your ducts are not even collected in the first place. From what i am observing, you are using link file right? if it is, then the solution i tagged you will do what you require

No,i’m not trying for linked file.(I used linked file only to try the script you tagged me)

when the for loop is applied (line 47 highlighted lines) then the output for duct is empty

when I remove the for loop it collect ducts

i know where are the error. your fundamentals are wrong :slight_smile:
You shouldnt use wherepass like this.

it should be something like this instead.

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

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

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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

# Import DSCore nodes in Dynamo
clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import *

# Import python library
import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import os
import shutil
import math
# Import math library
from math import *

#Import Data and Time
from datetime import datetime
now = datetime.now()

#Import System Library
import System
from System.Collections.Generic import *
from System.IO import Directory, Path

# The inputs to this node will be stored as a list in the IN variables.
cate1 = UnwrapElement(IN[0])
cate2 = UnwrapElement(IN[1])
# Place your code below this line
doc = DocumentManager.Instance.CurrentDBDocument

catid1 = int(str(cate1.Id))
bic = System.Enum.ToObject(BuiltInCategory,catid1)
catid2 = int(str(cate2.Id))
bic2 = System.Enum.ToObject(BuiltInCategory,catid2)

catEles1= FilteredElementCollector(doc).OfCategory(bic).WhereElementIsNotElementType().ToElements()

catEles2 = FilteredElementCollector(doc).OfCategory(bic2).WhereElementIsNotElementType().ToElements()

eleId1 = [ele.Id for ele in catEles1]
ids = List[ElementId](eleId1)

clash = [FilteredElementCollector(doc,ids).WherePasses(ElementIntersectsElementFilter(catEle)).ToElements() for catEle in catEles2]

# Assign your output to the OUT variable.
OUT = catEles1 ,catEles2 ,clash


EDIT: Tested and it works

6 Likes

It Works!
Thanks For Helping this newbie :smiley: :+1: