Get list of categories parameters can be assigned to

Get list of categories parameters can be assigned to

juqing27
Contributor Contributor
2,498 Views
6 Replies
Message 1 of 7

Get list of categories parameters can be assigned to

juqing27
Contributor
Contributor

 

Hi. I'm trying to get a list of categories parameters can be assigned to - basically the built-in list from Revit shown when a project or shared parameter is created/added, yellow highlighted in the snapshot below.  The code I'm using now is 

Categories Cats = m_commandData.Application.ActiveUIDocument.Document.Settings.Categories;

 

The issue is, this gives me a much longer list than what Revit's showing (the yellow box). See right side of the snapshot. For example - 

  1. there are no "Electrical Spare/Space Circuits" or "Elevations" in the Revit interface, but they are present in the list provided by the above code.
  2. Also, in the Revit interface, there's only one sub-category shown under "Floors", which is "Slab Edges". However, in the list provide by code (right side of snapshot), there are many more.

Worst case scenario, I guess I may have to look at the Revit interface and manually get rid of what's not shown in there. But before I go down that road, just wonder if there is any better and cleaner way to filter the list and get what we see in Revit interface.

 

Thanks for the help,

Qing

 

juqing27_2-1678474765701.png

 

 

 

0 Likes
Accepted solutions (1)
2,499 Views
6 Replies
Replies (6)
Message 2 of 7

juqing27
Contributor
Contributor

As always, minutes after posting to the forum, I made some progress.. 🙂 I added two criteria to filter the categories (IsTagCategory == false && AllowsBoundParameters == true). I don't have a good understanding of what the "AllowsBoudnParameters" property does, but these two condition, combined, seem to be giving a very decent list that's very similar to what we see in Revit. HOWEVER, as shown in the snapshot below, there are little discrepancies here and there. For example - 

  1. Under "Stairs", Revit interface has 3 sub-categories, whereas the list generated by code is missing "Supports"
  2. list generated by code is missing some Structural categories. 

Basically, although very close to what I'm looking for, it seems like I filtered a little more than I should. Still would like to see what's the best/official/ADSK internal way to reproduce this list. Also, I've found @jeremytammik 's solution here - The Building Coder: Category Support for Shared Type and Instance Parameters (typepad.com). It's very helpful, but since it's 9 years ago....:D and there are more categories added to Revit since then, maybe there could be an updated solution as well?

 

Any advice is appreciated!

 

Qing

juqing27_0-1678476332516.png

 

0 Likes
Message 3 of 7

Yien_Chao
Advisor
Advisor

hi

 

i found with AllowsBounding() for each parameter works fine. this parameter is true if you can attach a parameter to the category.

 

doc = DocumentManager.Instance.CurrentDBDocument
collector = FilteredElementCollector(doc)

settings = doc.Settings
cats = settings.Categories

allowBound = [i.AllowsBoundParameters for i in cats]

OUT = [i.Name for i,j in zip(cats,allowBound) if j is True]

 

0 Likes
Message 4 of 7

juqing27
Contributor
Contributor

Hi Yien_Chao, thanks for your response. Yes the "AllowsBoundParameters" property seems to be very CLOSE to what's needed. However, it doesn't look right on a few categories. For example (see snapshot in my lost reply), the "Supports" sub-category under "Stairs" is showing up in Revit interface, which should mean that the "AllosBoundParameters" is true (if following our logic). However, it's actually false in this case and therefore NOT showing up in the list I generated by code.

 

So, feels like there's some more accurate way of doing this.

 

juqing27_0-1678481273111.png

 

0 Likes
Message 5 of 7

RPTHOMAS108
Mentor
Mentor
Accepted solution

AllowsBoundParameters is the way to go with this. There is a specific known issue with the stair supports category in that it wrongly reports false for this.

 

https://forums.autodesk.com/t5/revit-api-forum/binding-shared-parameters-to-stair-supports/m-p/66994...
https://forums.autodesk.com/t5/revit-api-forum/stair-support-parameter-binding/m-p/9687646/highlight...

 

Do you find any other examples of such false reporting? Needs highlighting again I expect i.e. there is no other meaning for 'AllowsBoundParameters'

Message 6 of 7

juqing27
Contributor
Contributor

Hi @RPTHOMAS108, thanks for pointing me to the previous discussion. That answered my question. And no, there's no other category I've found that's reporting falsely on the "AllowsBoundParameters" property.

 

A related but separate question is whether a certain category supports Type binding vs. Instance binding, for example Rooms can only do Instance. However, I can't figure out how to tell that difference from API. I found this old post from 2014 - Solved: Determine if Category supports Type parameter binding - Autodesk Community - Revit Products, in which a workaround of hardcoding a lookup table was provided. I wonder if there's any update regarding this that may let us do it not from hardcoding, but by harvesting live data from Revit? It's probably a long shot.... Thanks anyways!

 

Qing 

 

 

juqing27_0-1678508100719.png

 

0 Likes
Message 7 of 7

RPTHOMAS108
Mentor
Mentor

Rooms don't have Types so you could be checking Element.CanHaveTypeAssigned  but for that you need an example element so it is not ideal when all you have is categories.

 

Depending on what your task is I would probably instead of trying to replicate the UI features allow for a more open ended approach and log the failures. For example if creating a system to add multiple parameters to a project then assume a type binding is permitted and log the resulting failure when such an attempt fails.  The majority of times the end user knows the limitations of these aspects (they wouldn't try to add parameters to a Room type for example).

 

Otherwise I think it is functionality that needs to be requested via the Ideas section. There are a few situations like this where the the UI knows more about an empty model than the API.