Free your Revit model from duplicated Elements

March 26, 2018

 

 

This workflow has been built to enhance model validation and free the model from duplicated elements, it's applicable for any element that has geometry.

 

 

Concept: 

 

Every shape has a middle point (Centroid) which could be taken from Revit as (X, Y, Z) coordinates and depending on that we can build an assumption of any two elements that have the same centroid that could be duplicated. The created script can work with any type of element that can be transferred to geometry in dynamo. Such as, the case below where I will cover 4 types of elements [Walls, Columns, Beams and floors].

 

How does it work? 

 

1- Column, floors, Beams, ..etc.: There is only one rule to comply.  

 

     Rule (1): Centroid (element1) = Centroid (element2), check figure (1).

 

 

 

 

                                                                Figure (1)

 

 

 

2- Walls: To make this assumption applicable for walls we need to add more rules

 

        Rule 1:  Centroid (element1) = Centroid (element2), check figure (1).

 

        Rule 2:  The angle between the two elements equal zero that means the two elements parallel. With applying this rule we                             eliminate the chance of two elements have the same centroid but they are perpendicular. As you see in the figure (2)

 

 

 

 

 

 

 

 

                                                                                                                                           Figure (2)

 

 

The Script:

 

The script includes one input to specify the desired category.

Dynamo Script Request Here

 

Python Code:

 

  • You need to install the lunchbox package. Also, some of the below nodes are taken from popular packages and have been edited to meet the desired needs.

 

Wall Orientation by archi-lab:                                                                                                                       

 

# Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

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

# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

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

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

def ProcessList(_func, _list):
    return map( lambda x: ProcessList(_func, x) if type(x)==list else _func(x), _list )

def Unwrap(item):
    return UnwrapElement(item)

def GetExteriorWallDirection(item):
    if type(item) == Autodesk.Revit.DB.Wall:
        locationCurve = item.Location
        if locationCurve != None:
            curve = locationCurve.Curve
            direction = XYZ.BasisX
            if type(curve) == Autodesk.Revit.DB.Line:
                direction = curve.ComputeDerivatives(0, True).BasisX.Normalize()
            else:
                direction = (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize()
            exteriorDirection = XYZ.BasisZ.CrossProduct(direction)
            
            if item.Flipped:
                exteriorDirection = -exteriorDirection
            return exteriorDirection.ToVector()
    else:
        return "Not a Wall"

if isinstance(IN[0], list):
    walls = ProcessList(Unwrap, IN[0])
else:
    walls = [UnwrapElement(IN[0])]

try:
    errorReport = None
    output = ProcessList(GetExteriorWallDirection, walls)
except:
    # if error accurs anywhere in the process catch it
    import traceback
    errorReport = traceback.format_exc()


#Assign your output to the OUT variable
if errorReport == None:
    OUT = output
else:
    OUT = errorReport

 

 

Elements organizing:

 

#Copyright(c) 2018, Mohammad Nawar
#BIMhex, http://BIM-hex , mohadnawar@live.com

 

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

x = IN[0]
l1 = []
l2 = []
i1 = []
i2 = []
j = 0

for i in x:
    if i not in l1:
        l1.append(i)
        i1.append(j)
        j = j+1
    else:
        l2.append(i)
        i2.append(j)
        j = j+1

l4 = []
i4 = []
x = 0

for k in l1:
    y = 0
    l3 = []
    i3 = []
    for w in l2:    
        if k == w:
            l3.append(k)
            l3.append(w)
            l4.append(l3)
            i3.append(i1[x])
            i3.append(i2[y])
            i4.append(i3)

        y = y +1
    x = x +1
#Assign your output to the OUT variable.
OUT = i4

 

Duplicate indices by archi-lab:

 

#Copyright(c) 2015, Konrad Sobon
# @arch_laboratory, http://archi-lab.net

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

mylist = IN[0]

a, seen, result, unique = mylist, set(), [], []
u1 = []
for i in a:
    for idx, item in enumerate(i):
        if item not in seen:
            seen.add(item)
            unique.append(idx)        
            # First time seeing the element
        else:
            result.append(idx)      
    u1.append(unique)
        # Already seen, add the index to the result


#Assign your output to the OUT variable
OUT = u1, result

 

Delete Element:

 

import clr
clr.AddReference('RevitNodes')
clr.AddReference("RevitAPI")
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitServices')
from Autodesk.DesignScript.Geometry import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument

x = UnwrapElement(IN[0])
x = IN[0]
o = []

TransactionManager.Instance.EnsureInTransaction(doc)
for i in x:
    ID = Autodesk.Revit.DB.ElementId(i)
    doc.Delete(ID)
    o.append(True)

TransactionManager.Instance.TransactionTaskDone()

OUT = o

 

Message box:

 

#Copyright(c) 2017, john pierson
# @60secondrevit, http://sixtysecondrevit.com


import clr
import msvcrt

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

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
x = IN[0]
y = IN[1]
if y == True:
    button = TaskDialogCommonButtons.None
    result = TaskDialogResult.Ok
    TaskDialog.Show('User Text',"No duplicate elements detected",button)
else:
    button = TaskDialogCommonButtons.None
    result = TaskDialogResult.Ok
    TaskDialog.Show('User Text',x,button)

        

OUT = x

 

 

Please reload

Our Recent Posts

Auto Joining between Elements in Revit

February 6, 2020

Best practice for Clash Detection (Revit/Navis/Dynamo)

February 6, 2020

Floor Slicing

June 11, 2019

1/4
Please reload

Tags

Please reload

©2018 by Nawar.

  • YouTube Social  Icon
  • LinkedIn Social Icon