Custom/shared param in Project Info. Check to see if it's in file?

Custom/shared param in Project Info. Check to see if it's in file?

doni49
Mentor Mentor
916 Views
1 Reply
Message 1 of 2

Custom/shared param in Project Info. Check to see if it's in file?

doni49
Mentor
Mentor

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




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Accepted solutions (1)
917 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted 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.

 

0 Likes