Determine Location Attributes and Retrieve Key Elements

Here are two issues that we have visited in the past and seem to be worth recapitulating and summarising, on determining the
location attributes of
an element and retrieving all
key elements in a key schedule.

Determining the Location Attributes of a Component Element

Question: I have extracted data from a Revit model via DBLink.

Now I would like to establish a relation between a component element and its location-centric attributes, specifically its Level, Space, and the Room it is located in.

For example, for a CAV Terminal Unit component, I can determine the building that it is in and the Level that it is on, but not the Space or Room containing it.

Can you provide any insight on how to properly identify these attributes?

Answer: There are a number of different possibilities.

The simplest and most common one is to use the FamilyInstance Room and Space properties.

All elements that can be cast into FamilyInstance can be queried for their Level, Zone, Space, Room Name and Room Number properties.

You need to ensure that your models are correctly constructed, of course, or these properties may be unreliable.
If you find that to be the case, consult with an application engineer and product experts on how to fix it and ensure that this is avoided in the future.

If these properties do not fulfil your needs, or your element is not a family instance, there are several other ways as well.

Basically, all you need is some central point on the element of interest that can be passed in to the Document GetRoomAtPoint or GetSpaceAtPoint methods.

Such a point can be determined from the element Location property, bounding box, or from the element geometry.

We just recently looked at another example of using the GetRoomAtPoint method to

determine the neighbours of a room
.

For more complex queries, you can also use a filtered element collector in conjunction with the element location or bounding box.

In general, all search for and access to Revit database elements works through filtered element collectors.
It is the most efficient way, and in fact the only way.

I see you also mention DBLink.
I cannot say much about that, since it is a closed subscription product.
You would have to ask product support whether you can customise it or include additional properties in the output it generates.
What you certainly can do is use DBLink on its own as is, run your custom add-in generating additional data in parallel with it, and unite the two data streams in your analysis database.

Retrieving the Key Elements Used in a Key Schedule

Question: Is it possible to get all key elements used in a key schedule?

For example, I have a room and create a room style schedule.
The parameter that is added to rooms is of storage type ElementId.
I can then get that element from the document and it has parameters for each other parameter used in the key schedule that can be read or set.
This is great and gets me most of what I want.

However, what if there are keys that are not used anywhere in the model at present?
I don’t have a room to get the objects from.
The category on the key objects is null so I can’t filter that way.
I tried to use an ElementParameterFilter even though it is a slow filter to find the key value parameter (and just made it a numeric greater than -1 filter), but this returned no elements to me at all.

Is it possible to get the unused keys?

Answer: To provide some basic understanding on this topic, you can start by looking at the Revit user interface Wikihelp on

key schedules
and
the further explanations provided by this article on

understanding schedule keys
.
The comments on the latter discussion may be of interest for you and your issue as well.

A surprisingly simple method to access the set of all elements listed in a schedule is to instantiate a filtered element collector providing the schedule view as an initial input argument.
That returns exactly the desired elements.
This works for key schedules as well.


Comments

6 responses to “Determine Location Attributes and Retrieve Key Elements”

  1. Constantin Gherasim Avatar
    Constantin Gherasim

    Hi Jeremy,
    Excuse me please for asking here about a different topic, but I don’t know any other email address where I could ask different questions from time to time.
    I would like to know if there is any possibility (API or not) that I could define a shared parameter and then somehow display it in different languages depending upon the Revit language (like in French for French Revit and in English for the English version of Revit).
    This would be something similar to Revit built-in SHEET_SCALE built-in parameter which is displayed Échelle in French and Scale in English.
    Thank you for your attention,
    Constantin

  2. Dear Constantin,
    Thank you, cool question.
    Unfortunately, I am not aware of any such functionality, whether API or not.
    I have heard of developers defining different shared parameter text files reusing the same shared parameter GUID for different languages, but that is a bit different.
    A Revit add-in can be internationalised and localised by using resource DLLs, and these can also be specified via the add-in manifest.
    None of this addresses you exact need, though.
    All I can suggest is to file a wish list item through all conceivable channels, such as Autodesk product support, ADN, AUGI, direct contact to product managers etc.
    Cheers, Jeremy.

  3. Constantin Gherasim Avatar
    Constantin Gherasim

    Thank you for the quick response, Jeremy!
    Have a great day,
    Constantin :)

  4. Chandan Munnalal Kawad Avatar
    Chandan Munnalal Kawad

    Hello Jeremy,
    I have question regarding GetRoomAtPoint().
    I used get room data feature to get list of rooms.
    Using which I paased one of point of such room to test whether GetRoomAtPoint() picks up the room back.
    It always returns null.
    Here is the code.
    XYZ p = new XYZ(115.64,23.75,4.36); //these are actual points of a room
    Room r = doc.GetRoomAtPoint(p);
    if (r != null)
    {
    System.Windows.Forms.MessageBox.Show(r.Name);
    }
    Please highlight what I am missing. [New to Revit World]
    Thanks and Happy New Year

  5. Chandan Munnalal Kawad Avatar
    Chandan Munnalal Kawad

    Hello Jeremy,
    I wasn’t passing phase info [Phase Dependent Room Properties http://thebuildingcoder.typepad.com/blog/2011/02/phase-dependent-room-properties.html%5D
    It shows room no now.
    Thanks,
    Chandan Munnalal Kawad

  6. M.Vallée Avatar
    M.Vallée

    Hi Jeremy,
    Your fantastic blog is still useful for me, thanks a lot for sharing your work.
    “A surprisingly simple method to access the set of all elements listed in a schedule is to instantiate a filtered element collector providing the schedule view as an initial input argument. That returns exactly the desired elements. This works for key schedules as well.”
    This is what I successfully did. However I still have some trouble attempting to populate a Windows forms combobox datasource with the possible values for my key parameter : how can I get/add the “none” value, which is represented in the French Revit version by the string “(aucun)”, to the combobox datasource ?
    public static List GetPossibleKeyParamValues(Document document)
    {
    // Get key schedule from param name
    ViewSchedule key_schedule = Utils.GetKeyScheduleFromParameterName(document, “MyKeyParamName”);
    // Return elements of that key schedule
    if (null == key_schedule)
    return null;
    List res = new List(new FilteredElementCollector(document, key_schedule.Id));
    // How to add the “none” value to this Element list?
    // because what I get is Val1, Val2, …, Valn
    return res;
    }
    Then in the form init method :
    comboBox.DataSource = GetPossibleKeyParamValues(document);
    comboBox.DisplayMember = “Name”;
    Thanks in advance for your ideas :)
    M.VALLEE

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading