Tag Archives: Parameter

[PyRevitMEP] Shared Parameter Manager

Managing shared parameters is a pain. The standard Revit GUI makes hard to create/manage a lot of parameters. The first version of the shared parameter manager is pretty old but was not as handy to use. Making an easy to use one was a tough job.

In this script is used a WPF DataGrid which nicely displays objects data and is able to auto generate a column for each attribute of an object including drop-down menu (aka combo-box) for enumeration, checkbox for boolean, textbox for sub-objects which can be represented by a string. But for some reason you have to click once to select the row and a second time to edit (check a box, activate drop-down or text edition) which makes it pretty unusable for edition. To solve this you need manually generate all columns with a data template, add handler to make bidirectional communication between displayed data and data in the background really used, sorting etc…

Some subjects are more complex that expected like actually sorting. As often I found answers on stack overflow : https://stackoverflow.com/questions/16956251/sort-a-wpf-datagrid-programmatically

As always source code is available. You’ll find it on github : https://github.com/CyrilWaechter/pyRevitMEP

My first objective with this tool and other related tools is to be able to easily add IFC parameters to objects (families) and project in order to produce better IFC files thereby improving interoperability.

[Revit] Delete parameters including hidden ones

In some case you need add or delete many parameters. Spiderinnet did many great articles about parameters, here are 2 of them :

Create shared parameter

Create project parameter

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()

Cheers !

[Revit] Copy shared parameters from rooms of a linked file to your own spaces

It is very useful to be able to copy shared parameter from a linked file to you own file especially if you want to make a stable link to an external database or maintain data consistency between different models.

The Autodesk Space Naming Utility is very useful but limited to room/space number and name. With the following script methodology you are able to copy any shared or built in parameter.

Unfortunately, Space property «Room» return None when the room is in a linked file. Hopefully there is a workaround which has been highlighted here by Revitalizer. You can use the GetRoomAtPoint as followed (same in the other way to get space from room).

from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Mechanical import Space
from Autodesk.Revit.DB.Architecture import Room
from Autodesk.Revit.UI import UIApplication
from System import Guid

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
getselection = uidoc.Selection.GetElementIds
app = __revit__.Application

#reference desired link
for e in app.Documents:
	if e.Title == "[LinkName].rvt":
		lien = e

#Reference the parameter you want to copy by GUID or BuiltInParameter
paramguid = Guid("88938699-b86d-4efa-aeb6-ce66d17d7755")

t = Transaction(doc, "Copy shared parameter from rooms to spaces")

t.Start()
#Get all spaces in the current project
for space in FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_MEPSpaces):	
	if space.Location != None: #Check if the space is placed
		#Get room at space insertion point location. Credit to Revitalizer : https://forums.autodesk.com/t5/revit-api/mep-space-class-room-property-returns-null-with-linked-models/td-p/3650268
		room = lien.GetRoomAtPoint(space.Location.Point)
		#Check if there is actually a room at this location
		if room != None:
			#Call desired parameter in both room and space
			spaceparam = space.get_Parameter(paramguid)
			roomparam = room.get_Parameter(paramguid)
			try:
				#Try to set space parameter value with room parameter value. It can fail if value is null for exemple 
				spaceparam.Set(roomparam.AsString())
			except:
				pass
t.Commit()

__window__.Close()