I have a custom/shared parameter in the Project Info of my template. I created an add-in that sets the value for this parameter.
But I need to confirm the parameter is actually there (such as if we receive a rvt file from someone outside our office, I don't want the fact that the parameter isn't in the file to cause a problem).
I've been searching for infor on this and the help file only says "This chapter introduces how to gain access to shared parameters through the Revit Platform API" but then doesn't give any more info. Really helpful -- NOT. 🙂
I'm working with Revit 2014.
Don Ireland
Engineering Design Technician
Solved! Go to Solution.
Solved by Scott_Wilson. Go to Solution.
For Revit 2014, something like this is probably what you need:
Autodesk.Revit.DB.Document dbDoc = commandData.Application.ActiveUIDocument.Document;
Parameter myParam = dbDoc.ProjectInformation.get_Parameter("Name of my parameter"); if(myParam != null) { // Set my parameter } else { TaskDialog("Whoops","Where's my parameter?"); }
Note that get_Parameter("name") is obsolete in the 2015 API and is replaced by LookupParameter("name") and GetParameters("name").
For shared parameters where the GUID is known, I'd suggest replacing the second line with:
Parameter myParam = dbDoc.ProjectInformation.get_Parameter(myParameterGuid);
You can also loop though all parameters and see if your's is there with:
foreach(Parameter param in dbDoc.ProjectInformation.Parameters) { if(param.Definition.Name == "Name of my parameter") { // Set my parameter
break; } }
Or again, for shared parameters a better way is:
foreach(Parameter param in dbDoc.ProjectInformation.Parameters) { if(param.IsShared && param.GUID == myParameterGuid) { // Set my parameter } }
The looping method can be useful for when you want to set many parameters of a single element at one time. One thing to watch out for though, is that multiple parameters with the same name can be assigned to an element. This is why I suggest using the parameter's GUID if it is shared so that there is no mistake of which parameter you are modifying. Similarly, if the parameter is definitely not shared, check for !param.IsShared to make sure you aren't getting a shared doppleganger.