This is the 1024th post on The Building Coder, just to top off our recent 5-year and 1000th post celebration.
The decimal number 1024 equals 2^10, i.e. 10.000.000.000 in binary format, hence the large number of zeroes in the title :-)
I am also still away on vacation and this is the second post in my absence – or 10th, in binary format :-) – dealing with retrieving ElementType parameters, the ADN Xtra labs built-in parameter checker and a BipChecker update for Revit 2014.
Meanwhile, I hope you are enjoying the break as much as I am :-)
Retrieving ElementType Parameters
I want to present a small enhancement to the built-in parameter checker included in the ADN Xtra labs.
The reason for looking at it again is to answer the following frequently recurring question:
Question: I know how to retrieve the element properties form an object, e.g. a column instance, using the Element.Parameters collection.
However, how can I access the column type properties, please?
Answer: For a given element E, you can ask for the element id of its type T by calling the GetTypeId method. Pass that in to the document GetElement method, access the T object instance itself, and retrieve the Element.Parameters collection from that.
The ADN Xtra Labs Built-in Parameter Checker
The ADN Xtra labs built-in parameter checker loops over all defined BuiltInParameter enumeration entries and checks to see whether a value can be retrieved for each of the corresponding parameters on a selected element.
Please be aware that an enhanced version of this built-in parameter checker was published as a separate BipChecker add-in back in 2011. We'll take another look at that below.
The user is prompted to select an element using the GetSingleSelectedElementOrPrompt method, which supports all conceivable selection facilities, including:
- Pre-selection before launching the command.
- Post-selection after launching the command.
- Entering a numeric element id to select an invisible element.
It achieves this by presenting a small prompt message:
The prompt is obviously only displayed if no pre-selection was made.
The code also initialises the isSymbol flag to false:
Element e = LabUtils.GetSingleSelectedElementOrPrompt( uidoc ); bool isSymbol = false;
The previous code was implemented before the introduction of the Element.GetTypeId method, so it just checked for a family instance like this:
// // for a family instance, ask user whether to // display instance or type parameters; // in a similar manner, we could add dedicated // switches for Wall --> WallType, // Floor --> FloorType etc. ... // if( e is FamilyInstance ) { FamilyInstance inst = e as FamilyInstance; if( null != inst.Symbol ) { string symbol_name = LabUtils.ElementDescription( inst.Symbol, true ); string family_name = LabUtils.ElementDescription( inst.Symbol.Family, true ); string msg = "This element is a family instance, so it " + "has both type and instance parameters. " + "By default, the instance parameters are " + "displayed. If you select 'No', the type " + "parameters will be displayed instead. " + "Would you like to see the instance " + "parameters?"; if( !LabUtils.QuestionMsg( msg ) ) { e = inst.Symbol; isSymbol = true; } } }
I updated the code to be more generic and handle all kinds of element type relationships by checking whether the GetTypeId method returns a valid element type id like this:
ElementId idType = e.GetTypeId(); if( ElementId.InvalidElementId != idType ) { // The selected element has a type; ask user // whether to display instance or type // parameters. ElementType typ = doc.GetElement( idType ) as ElementType; Debug.Assert( null != typ, "expected to retrieve a valid element type" ); string type_name = LabUtils.ElementDescription( typ, true ); string msg = "This element has an ElementType, so it has " + "both type and instance parameters. By " + "default, the instance parameters are " + "displayed. If you select 'No', the type " + "parameters will be displayed instead. " + "Would you like to see the instance " + "parameters?"; if( !LabUtils.QuestionMsg( msg ) ) { e = typ; isSymbol = true; } }
If an element that has a valid type assigned to it is selected, e.g. a wall, the code detects this and prompts the user to choose whether to display its instance or type properties:
If instance properties are chosen, the following list of parameters on the wall itself is displayed:
If type properties are chosen, the parameters are retrieved from the wall type instead:
Here is version 2014.0.0.3 of the ADN Training Labs for Revit 2014 including the updated built-in parameter checker.
BipChecker Update for Revit 2014
I went on planning to implement the same enhancement in the stand-alone BipChecker add-in, only to discover two things:
- It has not been updated since its original publication in the year 2011, for Revit 2012.
- It has already implemented a more sophisticated check than the one I describe above.
To see the more sophisticated check for various kinds of element types implemented by BipChecker, please search for 'CanHaveTypeAssigned' in the initial BipChecker publication.
I updated it for Revit 2014, fixing some compilation errors and disabling the architecture mismatch warning; here is BipChecker_2014.zip containing the new version.
Back to my vacation again... Meanwhile, I wish you a wonderful time as well!