Accessing Revit 2016 Global Parameters

Accessing Revit 2016 Global Parameters

rhanzlick
Advocate Advocate
2,295 Views
9 Replies
Message 1 of 10

Accessing Revit 2016 Global Parameters

rhanzlick
Advocate
Advocate

Hello All,

I am working on a Revit 2016 program in which I'd like to access the value of a Global Parameter. From working in the API I understand the following things exist:

 

Autodesk.Revit.DB.GlobalParametersManager

Autodesk.Revit.DB.GlobalParameter

 

However, I haven't quite figured out how to employ these, and I can't seem to find any information about them in the SDK.

 

The current way I am trying to implement them is something like this:

//**********************************************************************

//***************************Start Here*********************************

 

ElementId globalParam1 = GlobalParametersManager.FindByName(doc, "Global Parameter 1");
if (globalParameter1 == null)
{
TaskDialog.Show("GP Error 1", "There was a problem finding Global Parameter 1.");

break;
}


Element gp1Element = doc.GetElement(globalParam1);
double gp1 = gp1Element.LookupParameter("Value").AsDouble();

 

//****************************Fin***************************************

//**********************************************************************

 

 

Any help on how to access these values or locations of some documentation containing info about using/accessing Global Parameters with the Revit API would be greatly appreciated!

 

Thanks In Advance,

RH

 

 

 

 

Accepted solutions (2)
2,296 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Try casting gp1Element to a GlobalParameter and then use the GlobalParameter.GetValue() method.  There's a plethora of info in the main GlobalParameter class page in the API help.

0 Likes
Message 3 of 10

rhanzlick
Advocate
Advocate

Thanks for your quick reply, I have begun to implement your casting suggestion.... will post results!

0 Likes
Message 4 of 10

rhanzlick
Advocate
Advocate
*Edit* Also I was working with the 2016 SDK and not using R2 so I am currently updating to R2 2016 Revit SDK
0 Likes
Message 5 of 10

rhanzlick
Advocate
Advocate

Okay so I haven successfully cast it as a GlobalParameter and used the x.GetValue() command on it. The issue now is that it will not let me use the value as a double (the parameter value is a decimal value). I have tried to use both the "x.AsDouble()" and "x.AsValueString()" and they also do not work. When I output the "x.GetValue().ToString()" it does not tell me the parameter value, but only that it is "Autodesk.Revit.DB.DoubleParameterValue".

 

What am I missing?

0 Likes
Message 6 of 10

Anonymous
Not applicable
Accepted solution

If you look at the DoubleParameterValue members there is a "Value" property.  So it should be x.GetValue().Value and returns a double.

Message 7 of 10

rhanzlick
Advocate
Advocate
I have tried that and ".Value()" does not appear to be a valid method for ".GetValue()"
0 Likes
Message 8 of 10

Anonymous
Not applicable

Its a property.  Not a method.  So remove the parenthesis.

0 Likes
Message 9 of 10

rhanzlick
Advocate
Advocate
It does not appear to work as either one.
0 Likes
Message 10 of 10

rhanzlick
Advocate
Advocate
Accepted solution
***Final Update***

The final trick was casting from Element to GlobalParameter, then casting again from GlobalParameter to (your recommended) DoubleParameterValue (used with the x.GetValue() method).

Once it was cast as a DoubleParameterValue I was able to use your recommended x.GetValue().Value property, and it all worked out exactly as I'd hoped.
Thanks for your help, it is much appreciated!