Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

1 REPLY 1
SOLVED
Reply
Message 1 of 2
doni49
841 Views, 1 Reply

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

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.

1 REPLY 1
Message 2 of 2
Scott_Wilson
in reply to: doni49

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.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community