Some Revit addins and extensions are adding many parameters to you project. Some are not even visible to the user. It means that you have to use API to remove it. In most common case you’ll never see it unless you use Revit Lookup. But when you export your model or do a duct pressure loss report it appears on it. So I made a script to get quickly rid of unwanted parameters (hidden or not).
from Autodesk.Revit.DB import *
from System import Guid
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application
#Retrieve all parameters in the document
params = FilteredElementCollector(doc).OfClass(ParameterElement)
filteredparams = []
#Store parameters which has a name starting with "magi" or "MC"
for param in params:
if param.Name.startswith(("magi", "MC")): #startswith method accept tuple
filteredparams.append(param)
print param.Name #To check if a parameter in the list is not supposed to be deleted
#Delete all parameters in the list
t = Transaction(doc, "Delete parameters")
t.Start()
for param in filteredparams:
doc.Delete(param.Id)
t.Commit()
Sometimes you need to add new temperature in your project for at least 3 reasons :
When you use SI units Revit default fluids are bugged. I have seen them bugged for more than 5 years… Templates were made in Fahrenheit and some temperatures just don’t work when converted into °C or K.
Revit default fluids don’t have enough temperatures. About 5K between each and they usually just don’t fit the temperature you need in your project.
Water, ethylene and propylene glycol are the only default fluid available.
Here is a script example to add water to Revit. This way you can add any fluid available in CoolProp to Revit :
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
from Autodesk.Revit.DB.Analysis import *
from Autodesk.Revit.DB.Plumbing import *
from Autodesk.Revit.Exceptions import *
from Autodesk.Revit.UI import TaskDialogCommonButtons
from Autodesk.Revit.UI import TaskDialogResult
import ctypes
#Load CoolProp shared library and configure PropsSI c_types units
CP = ctypes.cdll.LoadLibrary(r"E:\Cyril\Dropbox\CVC\BIM_Revit\ScriptsPython\dll\CoolProp.dll")
PropsSI = CP.PropsSI
PropsSI.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_double, ctypes.c_char_p, ctypes.c_double, ctypes.c_char_p)
PropsSI.restype = ctypes.c_double
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
#Set desired fluid, initial temperature(freezing temperature ?), desired pressure for properties call
fluid = 'Water'
t_init = 273.15
pressure = 101325
#Check if fluid_type exist and create it if not
fluid_type = FluidType.GetFluidType(doc, fluid)
if fluid_type == None:
t = Transaction(doc, "Create fluid type")
t.Start()
FluidType.Create(doc, fluid)
t.Commit()
fluid_type = FluidType.GetFluidType(doc, fluid)
#Add new temperature with associated heat capacity and viscosity
t = Transaction(doc, "Add temperature")
t.Start()
for i in range(1,100):
#Call CoolProp to get fluid properties and convert it to internal units if necessary
temperature = 273.15+i
viscosity = UnitUtils.ConvertToInternalUnits(PropsSI('V','T',t_init+i,'P',pressure,fluid),DisplayUnitType.DUT_PASCAL_SECONDS)
density = UnitUtils.ConvertToInternalUnits(PropsSI('D','T',t_init+i,'P',pressure,fluid),DisplayUnitType.DUT_KILOGRAMS_PER_CUBIC_METER)
#Catching exceptions and trying to overwrite temperature if asked by user in the TaskDialog
try:
fluid_type.AddTemperature(FluidTemperature(temperature,viscosity,density))
except ArgumentException:
result = TaskDialog.Show("Error", "Temperature already exist, do you want to overwrite it ?",TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel, TaskDialogResult.Yes)
if result == TaskDialogResult.Yes:
try:
fluid_type.RemoveTemperature(temperature)
fluid_type.AddTemperature(FluidTemperature(temperature,viscosity,density))
except ArgumentException:
TaskDialog.Show("Overwrite error", "Temperature is currently in use and cannot be overwritten")
elif result == TaskDialogResult.No:
pass
else:
break
t.Commit()
Someone asked an exemple of ISelectionFilter on RevitPythonShell group almost a week ago. I don’t know if he still needs it but anyway, it’s interesting to show this other way to filter. In this exemple we allow user only to select a duct. Let see the code snippet :
from Autodesk.Revit.UI.Selection import *
class CustomISelectionFilter(ISelectionFilter):
def __init__(self, nom_categorie):
self.nom_categorie = nom_categorie
def AllowElement(self, e):
if e.Category.Name == self.nom_categorie:
return True
else:
return False
def AllowReference(self, ref, point):
return true
try:
ductsel = uidoc.Selection.PickObject(ObjectType.Element,
CustomISelectionFilter("Ducts"),
"Select a Duct")
except Exceptions.OperationCanceledException:
TaskDialog.Show("Opération annulée","Annulée par l'utilisateur")
__window__.Close()
Here in action :
Here is another exemple to select only objects inherited from MEPCurve (Cable Tray, Wire, InsulationLiningBase, Duct, FlexDuct, FlexPipe, Pipe) :
from Autodesk.Revit.UI.Selection import *
class CustomISelectionFilter(ISelectionFilter):
def __init__(self, element_class):
self.element_class = element_class
def AllowElement(self, e):
if isinstance(e, self.element_class):
return True
else:
return False
def AllowReference(self, ref, point):
return true
try:
ductsel = uidoc.Selection.PickObject(ObjectType.Element,
CustomISelectionFilter(MEPCurve),
"Select a Duct")
except Exceptions.OperationCanceledException:
TaskDialog.Show("Opération annulée","Annulée par l'utilisateur")
__window__.Close()