Setting shared parameter on sheet with python?

I’m working on a sheet generation tool, and want to assign several shared parameters (already created and available to sheets in my model) different values. It seems like I can’t set these using .get_parameter and .set parameters like I can with regular parameters. How can I set shared parameter values with Python?

I don’t know exactly how far you have developed your code, but the first thing you may want to check is using the Parameter property rather than the get_Parameter() method which has been obsolete for quite a few years. As you are using a shared parameter, you are best off using the shared parameter’s GUID along with the Parameter property of your Element (which is an element located on one of your sheets). You can go about getting the GUID in many different ways.

You can hard-code the value and construct a valid Guid like this

from System import Guid
sp_guid = Guid("307aa8ca-6816-4d1d-ad15-bf03bc0438f0")
# Assume element is a valid Element in your document
parameter = element.Parameter[sp_guid]

You can also get the GuidValue property of a SharedParameterElement:

# Assume doc is already defined as the current document
# and the necessary classes are imported from Autodesk.Revit.DB namespace
shared_params = FilteredElementCollector(doc).OfClass(SharedParameterElement)
guids = [sp.GuidValue for sp in shared_params]
# From here you will have to filter the guid list for only the desired parameters

How can I get the corresponding shared parameter name for each GUID value? Is the GUID value the same for each instance of the parameter on my model sheets?

If you open your shared parameters file in a text editor, you will see something like this:

Here we can see that I only have one shared parameter called “SampleParameter” and its GUID is 126b9117-370c-477b-aed9-dcad4617467f.

Here’s an example where I set a sample value to the instance parameter of each of the sheets in my document:

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import FilteredElementCollector, ViewSheet

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

from System import Guid

doc = DocumentManager.Instance.CurrentDBDocument
sheets = FilteredElementCollector(doc).OfClass(ViewSheet)

# Hard coded GUID value of the desired shared parameter
guid = Guid('126b9117-370c-477b-aed9-dcad4617467f')

TransactionManager.Instance.EnsureInTransaction(doc)
for sheet in sheets:
	sheet.get_Parameter(guid).Set('Sample Value')
TransactionManager.Instance.TransactionTaskDone()

I mentioned before that the get_Parameter() method is obsolete, but I couldn’t actually get it to work using the Parameter property (it kept throwing a TypeError, expecting a BuiltInParameter even though a Guid and Definition are both acceptable).

1 Like

Thanks! Got it working now…

1 Like