Get definition of built-in parameter with-out having an element

Get definition of built-in parameter with-out having an element

SamBerk
Advocate Advocate
2,896 Views
4 Replies
Message 1 of 5

Get definition of built-in parameter with-out having an element

SamBerk
Advocate
Advocate

Hi All

 

I want to get the StorageType UnitType and Parameter Type from built-in parameters when I don't have elements in my model that are using this parameter.

 

Is it possible to get the parameter definition of a built-in parameter with-out having an element in the model?

 

0 Likes
Accepted solutions (1)
2,897 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @SamBerk ,

try using the below link

built-in-parameter-name-and-labelutils.html 

https://www.revitapidocs.com/2020/8cdbbb5c-a21e-ad1d-e9a3-6535f5d27894.htm 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

aignatovich
Advisor
Advisor
Accepted solution

Hi!

 

It is simple to get a storage type of the parameter. Just use document.get_TypeOfStorage(BuiltInParameter...

 

Getting built-in parameter unit type is a bit more complicated. If you know the category parameter belongs to, you can create a view schedule in temporary transaction. You can find your parameter in schedule.Definition.GetSchedulableFields list:

var schedulableField = schedule
	.Definition
	.GetSchedulableFields()
	.Where(x => x.FieldType == ScheduleFieldType.Instance || x.FieldType == ScheduleFieldType.ElementType)
	.First(x => x.ParameterId == new ElementId(BuiltInParameter....));

Then add this schedulable field to the schedule, and get a schedule filed unit type:

schedule.Definition.AddField(schedulableField);
var unitType = schedule.Definition.GetField(0).UnitType;

This method works both for shared and built-in parameter.

Message 4 of 5

SamBerk
Advocate
Advocate

Thanks @aignatovich for your help

 

But how can I know the ParamaterType for example Length, Number, Integer, Text, Area, Yes/No, etc?

0 Likes
Message 5 of 5

floretti
Advocate
Advocate

I know this is an oldish post but I've been trying to get a built in parameter (elements' Phase Created) without having any elements in my project so I can setup some view filters and I managed to get at least their Ids via the below, which is a bit simpler. Note this currently works for 2024 and it may stop working in the future with API changes.

 

ForgeTypeId phaseCreatedTypeId = ParameterUtils.GetParameterTypeId(BuiltInParameter.PHASE_CREATED);
BuiltInParameter phaseCreatedBuiltInParam = ParameterUtils.GetBuiltInParameter(phaseCreatedTypeId);
ElementId phaseCreatedParamId = new ElementId(phaseCreatedBuiltInParam);

 

0 Likes