Get BuiltInParameter by Id

Get BuiltInParameter by Id

PieterL_TM
Advocate Advocate
848 Views
8 Replies
Message 1 of 9

Get BuiltInParameter by Id

PieterL_TM
Advocate
Advocate

In my script, I get an Id of a BuiltInParameter (e.g. '-1002300' )
How can I get the BuiltInParameter from this Id?
doc.GetElement() returns none.

 

What is the correct way to do this

0 Likes
Accepted solutions (1)
849 Views
8 Replies
Replies (8)
Message 2 of 9

jeremy_tammik
Alumni
Alumni

You can obtain the BuiltInParameter enumeration value from its integer representation using the standard C# procedure, so simply search the Internet for something like "c# get enum from int" or read a basic C# tutorial:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 9

PieterL_TM
Advocate
Advocate

Okay so two things.

- I'm writing in python (forgot to say that)

- Imagine that I understand Revit API, but little about programming. I have no idea what casting means or does.

I didn't post here because I'm to lazy to google, I posted here because everything you find online assumes you're already a master programmer.

0 Likes
Message 4 of 9

jeremy_tammik
Alumni
Alumni

OK, so a thing or two from me:

  

  • I am not a Python user
  • I am trying to help you as best I can
  • I am trying to be efficient, so I can help others as well
  • I searched next for "cast python int enum":
  • https://duckduckgo.com/?q=cast%20python%20int%20enum
  • I think you might be capable of doing so as well, even as a non-master programmer

  

Sorry for answering in the same vein... I have way too far mirroring neurons... please excuse that. And let's have fun, be friendly and supportive. I am afraid that I am often a bit terse, in addition to that.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 9

studio-a-int
Advocate
Advocate

Use this code in Python to get the ParameterElement from idOfYourParameter:

parameterFromId = activeDoc.GetElement(ElementId(int(str(idOfYourParameter))))

0 Likes
Message 6 of 9

PieterL_TM
Advocate
Advocate

It returns 'none', With your line you convert an Id to a string to an integer and then back to an Id, so same thing we started with.
Since I'm looking for a BuiltInParameter, it returns 'none'

0 Likes
Message 7 of 9

studio-a-int
Advocate
Advocate

If returns None, you are using an Id that is not valid. Check first to make sure you have the correct Id. To test that, run the code below. Pick up one of the ids listed and run it in the line I posted for you. You will see that works if you have the correct Id value, otherwise you are getting None.

 

parameters = FilteredElementCollector(activeDoc).OfClass(Autodesk.Revit.DB.ParameterElement).ToElements()
parametersNames = [i.Name for i in parameters]
listParaNamesParaTypes = zip(parametersNames, parameters)

0 Likes
Message 8 of 9

mhannonQ65N2
Collaborator
Collaborator

There is no ParameterElement for a BuiltInParameter. If you want its name, you can use LabelUtils.GetLabelFor(BuiltInParameter).

 

To get the BuiltInParameter from the integer id in python, try:

bip = BuiltInParameter(id)

 

0 Likes
Message 9 of 9

PieterL_TM
Advocate
Advocate
Accepted solution

I asked someone personally, this ended up doing the trick:

from System import Enum
param = Enum.ToObject(BuiltInParameter, param_id.Value)

Where param_id is the id of the BuiltInParameter.

 

Maybe there are easier solutions, but this was the first to work for me

0 Likes