In Dex:
00.Boiler Plate Code
# From JagadeeshKumar.Reddi works*
# reddi.jagadeeshkumar116@outlook.com
# visit https://www.5pillars.one/
# Boilerplate Code
import clr
#importing .NET's Common Language Runtime
clr.AddReference('RevitAPI')
#Adding Revit API DLL's reference to clr
from Autodesk.Revit.DB import FilteredElementCollector,BuiltInCategory,ViewPlan,ElementId,FilterElement
#importing Classes related to current scipt
clr.AddReference('RevitServices')
#Adding Revit Services DLL's reference to clr
from RevitServices.Persistence import DocumentManager
#importing Document Manger
from RevitServices.Transactions import TransactionManager
#importing Transaction Manger
#import List Functions
clr.AddReference("System")
from System.Collections.Generic import List
01.Detect Un Used Filters
This Script enable us to detect Unused Filters in current Revit Project.
As per Revit User Interference it is not possible to detect Un used Filters.
We Have developed a Dynamo script that enable to detect unused filters.
How to Detect Unused Filters?
It is very often, we create several view filters to represent different ASMEP entities on Sheet.
As Project goes on, we creates a lot of View Filters.
Revit UI cannot identify Used and Unused view filters from sheets.
To resolve this, We have developed a Dynamo Script which shows Unused Filters from sheet.
Objective:
Detect Unused Filters in current doucment
Method:
Collect all view plans.
Collect all filters applied to view plans
Filter Used filters from total filters
Unused Filters = Filters - Used Filters
Python Script:
# From JagadeeshKumar.Reddi works*
# reddi.jagadeeshkumar116@outlook.com
# visit https://www.5pillars.one/
#Current Doucment Defined
doc = DocumentManager.Instance.CurrentDBDocument
#collect all views
__Allviews = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()
#selection of viewplans from views
__ViewPlans = [v for v in __Allviews if isinstance(v, ViewPlan)]
#Defining Used filters Method
def _Col_UFilts(filters):
_Col_Filters=[]
for v in __ViewPlans:
#Extend method reduce nested loop into a single loop
_Col_Filters.extend(v.GetFilters())
#Remove Duplicates from Exisiting list
return _Col_Filters
#Applying Used filter method to current document & ICollection of Elements ID's
_Used_FilterIDs =List[ElementId](_Col_UFilts(doc))
#Defining UnUsed Filters Method
def _Col_UUFilts(filters):
UnusedFilters=[]
#Collecting all filters excludes Used Filter ID's
_Col_UUFilts=FilteredElementCollector(doc).OfClass(FilterElement).Excluding(_Used_FilterIDs).ToElements()
for f in _Col_UUFilts:
UnusedFilters.append(f.Name)
return UnusedFilters
#Applying UnUsed Filter Method to current doucment
UnusedFilters = _Col_UUFilts(doc)
#Get Number of unused Filters
Count = len(UnusedFilters)
OUT = Count,UnusedFilters
02.Delete Un Used Filters
In a Work in progress project, we have N number of filters, and we can't delete them one by one. We have developed a script that enable us to delete all unused filters at once.
Before delete, this script allows us to recheck and set true option from dynamo player UI we can delete all at once.
Python Script:
# From JagadeeshKumar.Reddi works*
# reddi.jagadeeshkumar116@outlook.com
# visit https://www.5pillars.one/
#Current Doucment Defined
doc = DocumentManager.Instance.CurrentDBDocument
#Unwrap Filters
__Del_UUF = UnwrapElement(IN[0])
# Get Unused list Names
_Del_List = [_Del_List.append(x.Name) for x in __Del_UUF ]
# if conforimation is true
if IN[1] == True:
#intiate Transcation
TransactionManager.Instance.EnsureInTransaction(doc)
#Iterate and delete each one from list
for d in __Del_UUF:
Id = d.Id
delete= doc.Delete(Id)
#Transaction closed
TransactionManager.Instance.TransactionTaskDone()
#outs deleted unused filters
out = _Del_List
else:
#Asks to make sure to delete
out = "Make true to delete"
03.View Type's Status
It's very often we create and duplicate N number view types like floor plan, celling plans, sections and 3D views.
we have place them very few on sheets especially sections.
we have developed a script which gives status of how many views placed on sheets and how many are remaining.
This Script shows View status of
1.Floor Plan's
2.Ceiling Plan's
3.3D View's
4.Drafting View's
5.Elevation's
6.Sections
It Gives Total counts of views, How many them placed on sheets and not placed on sheets.
Objective:
To find 6 different view Types status in current document.
Method:
Get all views and sheets by Filtered Element collector.
Get I List of sheets ID's.
Define two methods which will collect all view types and un used views.
Method 1 - Collect view types
which will give total count of view types.Method 2 - Collect Un Used Views
which will give unplaced views from sheets
Count 6 view types and subtract them from total views.
Views Placed on sheets = Total Views - Un Placed Views from Sheets.
Define Task Dialog to represent to User
Python Script:
# From JagadeeshKumar.Reddi works*
# reddi.jagadeeshkumar116@outlook.com
# visit https://www.5pillars.one/
#Current Doucment Defined
_Doc = DocumentManager.Instance.CurrentDBDocument
# Get All Views of Current Document
_Viws = FilteredElementCollector(_Doc).OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()
#Get All Sheets of Current Doucment
_Sht=FilteredElementCollector(_Doc).OfClass(ViewSheet).ToElements()
#Collecting Sheet ID's
_Shtid = [s.Id for s in _Sht]
#IList collection of sheets
_IShtid = List[ElementId](_Shtid)
#Method for Collect View Types
def _VT(ViewTypes):
_VT_s=[]
for x in _Viws:
if x.ViewType.ToString() ==ViewTypes:
_VT_s.append(x)
return _VT_s
#Method for To get Un used view Types
def _UuVT(UvwTyps):
_UViewTps = []
for x in _IShtid:
for v in UvwTyps:
if Viewport.CanAddViewToSheet(_Doc,x,v.Id)==True:
_UViewTps.append(v)
_UVws=[]
[_UVws.append(v) for v in _UViewTps if v not in _UVws]
return _UVws
#Collect Floor Plans Status
_FP=_VT("FloorPlan")
_TCFP=len(_FP)
_UUFp = _UuVT(_FP)
_CUUFp=len(_UUFp)
_CUFp = _TCFP - _CUUFp
#Collect and follow same code for "CeilingPlan" ,"ThreeD", "DraftingView","Elevation" and "Section"
#OutPut
OUT = _TCFP,_CUUFp,_CUFp,_TCCP,_CUUCp,_CUCp,_TCThD,_CUUThD ,_CUThD,_TCDv,_CUUDv,_CUDv,_TCElv,_CUUElv,_CUElv,_TCStns,_CUUStns,_CUStns
04. View Types Staus Delete
"Delete Views not placed on sheets" Script retrieves all the views those are not placed on sheets in the current Revit document and provides the user with the ability to delete unused views of different types. The user inputs whether they want to delete the unused views or not.
This script Delete 6 Different View Types, which is usually places on sheets.
01.Floor Plans
02.Ceiling Plans
03.3D Views
04.Drafting Views
05.Elevations
06.Sections
There are Two conditions or Warnings, when we run this script.
1.Current View is opened
Suppose Current View is not placed on sheets and opened. There is an warning it suggests to Switch/close current and view and refresh the script.
2.Excepton Arises
By iterating each and every view through python script, Dynamo expresses certain warnings. We added some try and exception blocks in python scripts, which suggests to refresh/run the script again until exception clears.
Objective:
To Detect and Delete Un used view types
Method:
_VT(ViewTypes):
A method is defined to collect views of a particular type.
It takes the ViewTypes as input and returns a list of views of that type.
_UuVT(UvwTyps):
A method is defined to get a list of unused views of a particular type.
It takes a list of view types as input and returns a list of unused views of those types.
_Del_UUE(VT,TOF,IP):
A method is defined to delete unused views of a particular type.
It takes the view types, total number of views, and a Boolean value indicating whether to delete the views or not as input.
It returns the number of deleted views and the number of remaining views.
Python Script:
# From JagadeeshKumar.Reddi works*
# reddi.jagadeeshkumar116@outlook.com
# visit https://www.5pillars.one/
# Get All Views of Current Document
_Viws = FilteredElementCollector(_Doc).OfCategory(BuiltInCategory.OST_Views).WhereElementIsNotElementType().ToElements()
#Get All Sheets of Current Doucment
_Sht=FilteredElementCollector(_Doc).OfClass(ViewSheet).ToElements()
#Collecting Sheet ID's
_Shtid = [s.Id for s in _Sht]
#IList collection of sheets
_IShtid = List[ElementId](_Shtid)
#Method to delte Unused Views
def _Del_UUE(VT,TOF,IP):
#if View Types are None
if TOF == 0:
CUUVT = "None"
CUVT = "None"
#if View types and Input is true
elif TOF > 0 and IP:
#try and exception to catch error
try:
#if length of unused view types are not zero
if len(_UuVT(VT)) > 0:
#Transaction Starts
TransactionManager.Instance.EnsureInTransaction(_Doc)
#for each view in unused view
for x in _UuVT(VT):
#if view is valid, delte view
if x.IsValidType:
_Doc.Delete(x.Id)
CUVT = TOF - len(_UuVT(VT))
CUUVT = len(_UuVT(VT)) +"Deleted Refresh The Script"
else:
#view is not valid then it gives refresh the script to delte
CUVT = TOF - len(_UuVT(VT))
CUUVT = len(_UuVT(VT)) + "Refresh The Script to Delete"
TransactionManager.Instance.TransactionTaskDone()
else:
#If length of unused views are none
CUVT = TOF
CUUVT = "None"
except Exception as e:
#if any exception arises script suggests to refresh the script or current view is opened switch or close the view
CUUVT="Refresh The Script"
CUVT = "An Error occured, check the current view is placed on sheets if it is, switch or close view"
elif TOF > 0 and not IP:
#If user input is false not to delete
CUUVT = len(_UuVT(VT))
CUVT = TOF - len(_UuVT(VT)) if len(_UuVT(VT)) else TOF
#return unused and used view types
return CUUVT, CUVT
#For Floor Plans
_FPIP = IN[0]
_FP = _VT("FloorPlan")
if all(v is None for v in _FP):
_TCFP,_CUUFP,_CUFP = ["None","None","None"]
else:
_TCFP = len(_FP)
_CUUFP,_CUFP = _Del_UUE(_FP,_TCFP,_FPIP)
#Collect Floor Plans Status
_FP=_VT("FloorPlan")
_TCFP=len(_FP)
_UUFp = _UuVT(_FP)
_CUUFp=len(_UUFp)
_CUFp = _TCFP - _CUUFp
#Collect and follow same code for "CeilingPlan" ,"ThreeD", "DraftingView","Elevation" and "Section"
OUT = _TCFP,_CUUFP,_CUFP
05.Revit Link Workset status
It is Very common to encounter many Revit links. For example, Main contractor working files generally have 50+ Revit links( Main contractors' working files, files from IFC and sub-contractors'). It can be a tedious procedure to check and change each Revit link file's workset if it relates to element visibility, detailing, and tagging.
Working Case:
This script has three working cases:
Case 1: Revit Links Name - None & Workset Name - None.
In this case, it will display the number of worksets and Revit links in the current project.
Case 2: Revit Link Name - "Enter any combination of Link Names" & Workset Name - None.
In this case, it will display all Revit links and their type worksets. You can easily configure how many Revit links exist with a particular name. For example, if you have Architecture files from the "ABC" company, and its file naming convention is like ABC-AR-1001, ABC-AR-1002, etc., Enter ABC-AR and run the script. It will extract all Architecture files related to ABC and their corresponding worksets.
Case 3: Revit Links Name - "Enter any combination of Link Names" & Workset Name - "Desired Workset Name".
In this case, it will display how many Revit links changed to the desired workset.
Run Case 1 again to check all Revit Link Type worksets' status.
Python Script:
# Collect all worksets
_Wrks = FilteredWorksetCollector(_Doc).OfKind(WorksetKind.UserWorkset).ToWorksets()
# Get Workset names //list comprehension
_W_Nms = [w.Name for w in _Wrks ]
#Get Count of Worksets
_W_Cnt = len(_W_Nms)
#collect all revit links
_Col_RvtLnks = FilteredElementCollector(_Doc).OfClass(RevitLinkType).ToElements()
# Get Revit Links names //list comprehension
_Rvt_Nms = [w.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString() for w in _Col_RvtLnks ]
#Get Count of Worksets
_Rvt_Cnt = len(_Rvt_Nms)
#Getting Workset Table
_Wrks_Tble = _Doc.GetWorksetTable()
#Revit Link Worksets for reference
_RvtLnk_Wrks =[ (_Wrks_Tble.GetWorkset(x.WorksetId)).Name for x in _Col_RvtLnks]
#Getting Workset Table
_Tble_Wrks = [ _Wrks_Tble.GetWorkset(x.WorksetId).Name for x in _Col_RvtLnks]
#Select Revit LInks
_Sel_RvtLnks= []
#for every in all Revit Links
for x in _Col_RvtLnks:
if IN[0] in x.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString() :
_Sel_RvtLnks.append(x)
#Select Revit LInks Counts
_Sel_RvtLnks_Cnt = len(_Sel_RvtLnks)
#Select Revit Links Names
_Sel_RvtLnks_Nms = []
for x in _Sel_RvtLnks:
_Sel_RvtLnks_Nms.append(x.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME).AsString())
#Select Revit Links Worksets
_SRvtLnk_Wrks =[ (_Wrks_Tble.GetWorkset(x.WorksetId)).Name for x in _Sel_RvtLnks]
#Preset Workset ID as None
D_Wrks_Id=None
D_Wrks_Nm=None
#if Workset Input is None
if not IN[1]:
_Wrks_Id=None
_Wrks_Nm="Provided Workset Name"
else:
#If workset is entered
for W in _Wrks:
if W.Name==IN[1]:
D_Wrks_Id=W.Id
D_Wrks_Nm=W.Name
for x in _Sel_RvtLnks:
#Transaction Manager Ensures in Transactions
TransactionManager.Instance.EnsureInTransaction(_Doc)
#CHange Workset to Desired Workset
(x.LookupParameter("Workset")).Set(int(str(D_Wrks_Id)))
#Close Transactions
TransactionManager.Instance.TransactionTaskDone()
# Output
OUT = _W_Cnt,_Rvt_Cnt,_Sel_RvtLnks_Cnt,_Sel_RvtLnks_Nms,D_Wrks_Nm, _SRvtLnk_Wrks
06.Sheet Views - Update View & Title Name
Summary:
In the process of presenting block wall or builder's work drawings, it is common to have multiple detail views on sheets. For example, one level of a builder's work may have one plan and a few sheets that represent openings of MEP entities.
After sections are drawn in floor plans and arranged on sheets, the detail numbers, View names and titles of the views do not match.
This requires us to spend time changing the detail numbers and titles on the sheets accordingly.
We have developed a Python script that sets the view name and title on the sheet according to its detail number from a given CSV file.
This script automates the process of updating the detail numbers and titles on the sheets, which saves us time and effort.
For Example in this Project, Sheet Number "5P-SF-CT-003" Have 20 Views. We have entered in excel 20 Detail numbers, View Names and Title on sheet Accordingly. Enter Unique name always otherwise Revit Gives "NameNotUnique" Error.
Script:
#Collect all sheets by using FilteredElement Collector
_CSHT = FilteredElementCollector(_Doc).OfClass(ViewSheet).ToElements()
#Collect all Sheet Numbers
_SHT=[]
for x in _CSHT:
_SHT.append(x)
#Collect all Sheet Numbers
_SHTN=[]
for x in _CSHT:
_SHTN.append(x.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString())
#Collect All View Port Detail Numbers
#Check Sheet ID
_SSID=None
#Get All View Ports
_SHVWi = []
#for every x in sheets
for x in _CSHT:
if IN[0] == x.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString():
_SSID= x.Id
#Collect all viewports on sheet
_SHVWi =x.GetAllViewports()
_rvtlnk=x.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString()+" - " + x.get_Parameter(BuiltInParameter.SHEET_NAME).AsString()
if not IN[0]:
_rvtlnk = "Enter Sheet Name"
#convert element IDs into elements
_SHVPT = []
for x in _SHVWi:
_SHVPT.append(_Doc.GetElement(x))
#Set input from CSV Files
_List=IN[1]
_PDN=IN[1][0]
_PVN=IN[1][1]
_PTS=IN[1][2]
#Check with Detail Numbers and set View Name and Title on sheet
_Set = []
_VN = []
_TON = []
for x in _PDN:
for y in _SHVPT:
if x == int(y.get_Parameter(BuiltInParameter.VIEWPORT_DETAIL_NUMBER).AsString()):
TransactionManager.Instance.EnsureInTransaction(_Doc)
(y.LookupParameter("View Name")).Set(str(_PVN[_List[0].index(x)]))
(y.LookupParameter("Title on Sheet")).Set(str(_PTS[_List[0].index(x)]))
TransactionManager.Instance.TransactionTaskDone()
_Set.append(_List[0].index(x))
_VN.append(_PVN[_List[0].index(x)])
_TON.append(_PTS[_List[0].index(x)])
#Transaction Manager Ensures in Transactions;
#Collect All Detail Numbetrs
OUT= _rvtlnk,len(_SHVWi)
07. Cable Tray Types & Routing Preference
This Script is divided into 3 Steps As Described Below........
1.Duplicate Cable Tray's Types
2.Duplicate Cable Tray's Fittings Types
3.Set Cable Tray Routing Preferences
A Dynamo Python Script that Duplicate Cable Tray Types and Fitting Types, Sets Type Comments and Description. Sets Cable Tray Routing Preferences as per Type Name of fittings accordingly.
There are Two Cases:
1. Create New Cable Tray Types for New Project
2.Add Additional Cable Tray for Existing Project
We have To create An CSV File, with Cable Tray Type Names, Type Comments and Desctiption. Add another column's of Default Cable Tray Fitting Families and Type Names.
Steps:
1.Create CSV File
2.Duplicate Cable Tray Types
3.Load Cable Tray Fitting Families
4.Duplicate Cable Tray Fitting Families
5.Set Routing of Existing Cable Tray Types
There are 7 types of routing preference for cable tray
Cable Tray have following fittings:
Horizontal Bend
Vertical Inside Bend
Vertical Outside Bend
Tee
Cross
Transition
Union
07.1. Duplicate Cable Tray Types
#Collect All Cable Tray Types
_CT_T = FilteredElementCollector(_Doc).OfClass(CableTrayType).WhereElementIsElementType()
#Check for Exisiting CT Type by input
_ET_ = None
for x in _CT_T:
if x.LookupParameter("Type Name").AsString() == IN[1]:
_ET_ = x
break
#Collect all Cable Tray Type Names
_ETT = []
for x in _CT_T:
_ETT.append(x.LookupParameter("Type Name").AsString())
#Definiton/Method to duplicate Cable Tray Types
def C_CT(_XCT,TC,TD):
for x in _XCT:
if x not in _ETT:
TransactionManager.Instance.EnsureInTransaction(_Doc)
try:
_NT = _ET_.Duplicate(x)
_NT.LookupParameter("Type Comments").Set(TC[_XCT.index(x)])
_NT.LookupParameter("Description").Set(TD[_XCT.index(x)])
except Exception as e:
return "Error duplicating cable tray type: " + str(e)
TransactionManager.Instance.TransactionTaskDone();
#IF Input is true to duplicate all Cable Tray Types by user input
if IN[2]:
NCT = C_CT(IN[0][0],IN[0][1],IN[0][2])
#IF Input is false, no execution of code
else:
NCT ="None"
#Collecting All Duplicated Cable Tray Types by USer Input
_ENTCT = len([x for x in IN[0][0] if x is not None and x not in _ETT])
07.2. Duplicate Cable Tray's Fitting Types
#Collecting All Family Symbols
_CCTF =FilteredElementCollector(_Doc).OfClass(FamilySymbol).ToElements()
#Filtereing only cable tray fittings family symbol
_CTF = []
for x in _CCTF:
if x.Category.Name == "Cable Tray Fittings":
_CTF.append(x)
#Select Cable Tray Fittings Part Type
_DF=[]
for x in _CCTF:
for y in IN[0][4]:
if x.LookupParameter("Type Name").AsString() == str(y):
_DF.append(x)
break
#Select based on Type Names
_ECTF = []
for x in _CTF:
_ECTF.append(x.LookupParameter("Type Name").AsString())
#Define Method to duplicate Cable tray fitting Types
def _DCTF(_N, TC, TD):
count = 0 # Counter variable to track the number of duplications
for x in _N:
for y in _DF:
if x not in _ECTF:
try:
TransactionManager.Instance.EnsureInTransaction(_Doc)
_NTF = y.Duplicate(x)
_NTF.LookupParameter("Type Comments").Set(TC[_N.index(x)])
_NTF.LookupParameter("Description").Set(TD[_N.index(x)]) # Increment the count for each duplication
except Exception as e:
return "Error duplicating cable tray type: " + str(e)
TransactionManager.Instance.TransactionTaskDone();
#IF Input is TRUE,Duplicate and set Parameters
if IN[1]:
NCTF=_DCTF(IN[0][0],IN[0][1],IN[0][2])
C_CT = len([x for x in IN[0][0] if x is not None and x not in _ECTF])
C_CTF = C_CT * 7
else:
NCTF="None"
C_CTF = "None"
# Return the CT list as output to the Dynamo workspace
OUT = C_CTF
07.3. Set Cable Tray Routing Preferences
#Collecting all MEP Curve Type
_CT_MEP = FilteredElementCollector(_Doc).OfClass(MEPCurveType).ToElements()
#Filterout by MEPCurve Type
_CT_MEPT = []
for x in _CT_MEP:
if x.Category.Name == "Cable Trays":
_CT_MEPT.append(x)
#Select as per Type Name
_CT_Typ = []
for x in _CT_MEPT:
_CT_Typ.append(x.LookupParameter("Type Name").AsString())
#Collect All Families
_CT_FC = FilteredElementCollector(_Doc).OfClass(Family).ToElements()
#FIlter out Family Types by Cable Tray Fitting Types
_CT_FFC = []
for x in _CT_FC:
if x.FamilyCategory.Name == "Cable Tray Fittings":
_CT_FFC.append(x)
#Define Method as per Part Type
def _CT_FT(PartName):
_CT_Family = []
for x in _CT_FFC:
if x.get_Parameter(BuiltInParameter.FAMILY_CONTENT_PART_TYPE).AsValueString() == PartName:
Fam_Sym = x.GetFamilySymbolIds()
Fam_Type = [x.Document.GetElement(symbol_id) for symbol_id in Fam_Sym]
Fam_TName = [symbol.Id for symbol in Fam_Type]
_CT_Family=[x for x in Fam_TName if x not in _CT_Family]
return _CT_Family
#Collecting all Channel Vertical Elblow Type
_Ch_VELB = []
for x in _CT_FFC:
if x.get_Parameter(BuiltInParameter.FAMILY_CONTENT_PART_TYPE).AsValueString() == "Channel Vertical Elbow":
_Ch_VELB.append(x)
#Select as per Family Name - Inside Bend
_Ch_VIB=[]
for x in _CT_FFC:
if x.Name == "02.CABLE TRAY VERTICAL INSIDE BEND":
VIB_Sym = x.GetFamilySymbolIds()
VIB_Type = [x.Document.GetElement(symbol_id) for symbol_id in VIB_Sym]
_Ch_VIB = [symbol.Id for symbol in VIB_Type]
#Select as per Family Name - Outside Bend
_Ch_VOB = []
for x in _CT_FFC:
if x.Name == "03.CABLE TRAY VERTICAL OUTSIDE BEND":
VOB_Sym = x.GetFamilySymbolIds()
VOB_Type = [x.Document.GetElement(symbol_id) for symbol_id in VOB_Sym]
_Ch_VOB = [symbol.Id for symbol in VOB_Type]
#Collect All Part types Families
_Ch_HB = _CT_FT("Channel Elbow")
_Ch_Tee = _CT_FT("Channel Tee")
_Ch_Crs = _CT_FT("Channel Cross")
_Ch_Trs = _CT_FT("Channel Transition")
_Ch_Un = _CT_FT("Channel Union")
# Set Method for Based on Part Type and CT Type Name
def _Set_CTF(_Ch,Bend):
_CT_MEPHB = []
for x in _CT_MEPT:
for y in _Ch:
if x.LookupParameter("Type Name").AsString() == (_Doc.GetElement(y)).LookupParameter("Type Name").AsString():
TransactionManager.Instance.EnsureInTransaction(_Doc)
x.LookupParameter(Bend).Set(y)
TransactionManager.Instance.TransactionTaskDone();
# Transaction Manager Ensures in Transactions
_CT_MEPHB.append(x)
#If Input is True sets all CT Types based on Part Types
if IN[1]:
_CT_SHB = _Set_CTF(_Ch_HB,"Horizontal Bend")
_CT_SIB = _Set_CTF(_Ch_VIB,"Vertical Inside Bend")
_CT_SOB = _Set_CTF(_Ch_VOB,"Vertical Outside Bend")
_CT_STee = _Set_CTF(_Ch_Tee,"Tee")
_CT_SCrs = _Set_CTF(_Ch_Crs,"Cross")
_CT_STrs = _Set_CTF(_Ch_Trs,"Transition")
_CT_Un = _Set_CTF(_Ch_Un,"Union")
#Count all family types
_M_CTT = 0
_M_CT = []
for x in _CT_MEPT:
for y in IN[0][0]:
if x.LookupParameter("Type Name").AsString() == str(y):
_M_CTT +=1
_M_CT.append(x.LookupParameter("Type Name").AsString())
# Return the CT lt as output to the Dynamo workspace
OUT =_M_CTT,_M_CT
08.Duct Systems & Routing Preference
Revit has Three Types of Duct systems by default.
1.Sypply Air
2.Return Air
3.Exhaust Air
The above three is also Default Duct system classifications. Any new system will be duplicates above with system classifications. This script creates different new duct system types based on their system classifications.
This script is divided into 3 steps:
8.1. Duplicate Duct system as per system Classification
8.2. Assign Material to Duct System Types
8.3. Duct System Color Graphic overrides
8.1.Duplicate Duct system as per system Classification
#Collecting Duct systems throught Filtered Element Collector
_DT_T = FilteredElementCollector(_Doc).OfCategory(BuiltInCategory.OST_DuctSystem).WhereElementIsElementType().ToElements()
#Get Duct Type Names from Collector
_EDT = [x.LookupParameter("Type Name").AsString() for x in _DT_T]
#Checking with CSV file,if CSV Duct system equals, it will duplicate new duct system types and sets Abbrevation
if IN[0]:
for x in IN[1]:
for y in _DT_T:
if str(x) == y.LookupParameter("Type Name").AsString():
TransactionManager.Instance.EnsureInTransaction(_Doc)
y.Duplicate(x)
y.LookUpParameter("Abbreviation").Set(IN[3][IN[1].index(x)])
TransactionManager.Instance.TransactionTaskDone;
#Length of duct systems created
_ENDT = len([x for x in IN[1] if x not in _EDT])
8.2.Assign Material to Duct System Types
mats = FilteredElementCollector(_Doc).OfClass(Material).ToElements()
#Gets Mateiral name in Current Project
nams = [m.Name for m in mats]
#Check and Mateiral set to Duct systems if material name matches with CSV File
if IN[0]:
for x in IN[1]:
for y in _DT_T:
for z in mats:
if str(x) == y.LookupParameter("Type Name").AsString() and str(IN[3][IN[1].index(x)]) == z.Name:
TransactionManager.Instance.EnsureInTransaction(_Doc)
y.LookupParameter("Material").Set(z.Id)
TransactionManager.Instance.TransactionTaskDone;
8.3.Duct System Color Graphic overrides
#Check and color RGB set to Duct systems matches with CSV File
if IN[0]:
for x in IN[1]:
for y in _DT_T:
if str(x) == y.LookupParameter("Type Name").AsString():
TransactionManager.Instance.EnsureInTransaction(_Doc)
R=IN[2][IN[1].index(x)]
G=IN[3][IN[1].index(x)]
B=IN[4][IN[1].index(x)]
y.LineColor = Color(R,G,B)
TransactionManager.Instance.TransactionTaskDone;
09. Pipe Systems & Routing Preference
This script is divided into 3 steps:9.1. Duplicate Pipe system as per system Classification9.2. Assign Material to Pipe System Types9.3. Pipe System Color Graphic overrides
Revit has 11 Types of Pipe systems by default.
Domestic Cold Water
Domestic Hot Water
Fire Protection Dry
Fire Protection Other
Fire Protection Pre-Action
Fire Protection Wet
Hydronic Return
Hydronic Supply
Other
Sanitary
Vent
The above 11 are also Default Pipe Duct system classifications. Any new system will be duplicated above with system classifications. This script creates different new Pipe system types based on their system classifications.
1. Duplicate Pipe system as per system Classification
#Collecting Duct systems throught Filtered Element Collector
_DT_T = FilteredElementCollector(_Doc).OfCategory(BuiltInCategory.OST_PipingSystem).WhereElementIsElementType().ToElements()
#Get Duct Type Names from Collector
_EDT = [x.LookupParameter("Type Name").AsString() for x in _DT_T]
#Checking with CSV file,if CSV Duct system equals, it will duplicate new duct system types and sets Abbrevation
if IN[0]:
for x in IN[1]:
for y in _DT_T:
if str(IN[2][IN[1].index(x)]) == y.LookupParameter("Type Name").AsString():
TransactionManager.Instance.EnsureInTransaction(_Doc)
y.Duplicate(x)
y.LookupParameter("Abbreviation").Set(IN[3][IN[1].index(x)])
TransactionManager.Instance.TransactionTaskDone;
2. Assign Material to Pipe System Types
#Collecting All materials by using Filtered Element collector
mats = FilteredElementCollector(_Doc).OfClass(Material).ToElements()
#Gets Mateiral name in Current Project
nams = [m.Name for m in mats]
#Collecting Duct systems throught Filtered Element Collector
_DT_T = FilteredElementCollector(_Doc).OfCategory(BuiltInCategory.OST_PipingSystem).WhereElementIsElementType().ToElements()
#Check and Mateiral set to Duct systems if material name matches with CSV File
if IN[0]:
for x in IN[1]:
for y in _DT_T:
for z in mats:
if str(x) == y.LookupParameter("Type Name").AsString() and str(IN[3][IN[1].index(x)]) == z.Name:
TransactionManager.Instance.EnsureInTransaction(_Doc)
y.LookupParameter("Material").Set(z.Id)
TransactionManager.Instance.TransactionTaskDone;
3.Pipe System Color Graphic overrides
#Collecting Duct systems throught Filtered Element Collector
_DT_T = FilteredElementCollector(_Doc).OfClass(PipingSystemType).WhereElementIsElementType().ToElements()
#Check and color RGB set to Duct systems matches with CSV File
if IN[0]:
for x in IN[1]:
for y in _DT_T:
if str(x) == y.LookupParameter("Type Name").AsString():
TransactionManager.Instance.EnsureInTransaction(_Doc)
R=IN[2][IN[1].index(x)]
G=IN[3][IN[1].index(x)]
B=IN[4][IN[1].index(x)]
y.LineColor = Color(R,G,B)
TransactionManager.Instance.TransactionTaskDone;
10.Select Elements Categories By ScopeBox
For Single or Multiple Category
In construction projects, we often divide the space into different areas. When we create models, we use scope boxes to represent these areas and make drawings accordingly. Sometimes, we need to assign information or quantities to elements within these areas. The usual way to do this involves selecting elements, filtering them by Categories, and adding information, which can be time-consuming and prone to errors.
This script automates this process. It quickly identifies the scope boxes for each area and automatically adds the required information to the elements within those areas. This automation takes only about five seconds, ensuring that it's both fast and accurate. It eliminates errors and makes the whole process much easier.
This is especially useful when the model changes over time. Instead of repeating the manual steps, the script handles everything automatically. This means less time spent on repetitive tasks and more time for productive work. Overall, this script improves efficiency and accuracy when dealing with different areas in a construction project.
SCRIPT:
# Select the current Revit View
_UIDoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
# Collect all Scope Boxes
# Note: The correct category for Scope Boxes is "OST_VolumeOfInterest"
_Scp_Bx = FilteredElementCollector(_Doc).OfCategory(BuiltInCategory.OST_VolumeOfInterest).ToElements()
#Define Method to make Input Categories to a list
def _ToList(IP):
OP1=IP.split(",")
OP2=OP1[::1]
return OP2
#Define Method to Get Categories of scope Box
def _SB(SBN):
#Collect Scope Box Elements,Categories,Message
_SBE = []
_SBC = []
_SBN = None
for x in _Scp_Bx:
if x.Name == SBN:
_SCP = x
_BO = _SCP.get_BoundingBox(_Doc.ActiveView)
_OBB = Outline(_BO.Min, _BO.Max)
_BE = BoundingBoxIsInsideFilter(_OBB)
_CBE = FilteredElementCollector(_Doc).WherePasses(_BE).ToElements()
_SBCN = [y.Category.Name for y in _CBE if y.Category is not None]
_SBE=[x for x in _CBE if x.Category is not None]
_SBC = list(set(_SBCN))
_SBN = SBN
break
else:
_SBE = "None"
_SBC = "None"
return _SBC,_SBE,_SBN
#Method to check Parameters are valid or not for selected elemetnts
def _Chk_Prmtr(ip,id):
parameter = None
#Checks if the parameter exists for the elements in the scope box
for x in id:
parameter = _Doc.GetElement(x).LookupParameter(ip)
return parameter
#Applying Methods to input
_SBCat,_SBAE,_ESBN=_SB(IN[0])
_SBC =_SBCat
_SBE =_SBAE
_SBN = _ESBN
#Filter Elements from selected scope box to Entered Categories
_ReCat = []
_ReCatID = []
for x in _SBE:
for y in _VEC:
if x.Category.Name == y:
_ReCat.append(x.Category.Name)
_ReCatID.append(x.Id)
#IList
_ReCatI=List[ElementId](_ReCatID)
#Select Elements in Active View
sel = _UIDoc.Selection.SetElementIds(_ReCatI)
#Change Parameter Values
if IN[2]:
#select Paramter and change Parameters
TransactionManager.Instance.EnsureInTransaction(_Doc)
for x in _ReCatID:
((_Doc.GetElement(x)).LookupParameter(IN[3])).Set(IN[4])
TransactionManager.Instance.TransactionTaskDone()
11. Cable Tray Fitting's Justification
In MEP coordination, we frequently use eccentric and concentric connections, often referred to as left-hand and right-hand connections. When procuring or ordering cable tray fittings, we need to specify the number of eccentric and concentric connections. This is required for various areas within the same project, especially in a progressive model where connections may change frequently during the coordination process. Quantifying cable tray fittings can be a time-consuming task due to the evolving nature of connections throughout the project.
SCRIPT:
#Define tolernace to compare nearly equal values
tolerance = 1e-6
#Define Mehod of limits to change Third and fourth quadrant to second or first
def _limits(x):
_Ale = math.degrees(x)
_Tv = _Ale # Assign a default value to _Tv
if 180 < _Ale < 270:
_Tv = _Ale - 180
elif 270 < _Ale < 360:
_Tv = _Ale - 270
return _Tv
#Assignin empty values
_ALHS = 0
_ARHS = 0
_AMHS = 0
#count LHS and RHS Cable tray fittings
_LHS = []
_RHS = []
#check each and every Cable tray fitting's LHS and RHS and assign accrodingly
if IN[0]:
for x in _CFT:
ALHS = _limits(x.LookupParameter("LHS").AsDouble())
ARHS = _limits(x.LookupParameter("RHS").AsDouble())
_LHS.append(ALHS)
_RHS.append(ARHS)
if abs(ALHS - ARHS) <= tolerance:
Justification = "CENTER"
_AMHS += 1
elif ALHS > ARHS:
Justification = "LEFT"
_ALHS += 1
elif ARHS > ALHS:
Justification = "RIGHT"
_ARHS += 1
else:
Justification = "None"
TransactionManager.Instance.EnsureInTransaction(_Doc)
x.LookupParameter("CT.Reducer Justification").Set(Justification)
TransactionManager.Instance.TransactionTaskDone()