10.000.000.000th Post and Element Type Parameters

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:

Element selection prompt

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:

Element type message

If instance properties are chosen, the following list of parameters on the wall itself is displayed:

List of instance parameters

If type properties are chosen, the parameters are retrieved from the wall type instead:

List of element type parameters

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:

  1. It has not been updated since its original publication in the year 2011, for Revit 2012.
  2. 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!


Comments

9 responses to “10.000.000.000th Post and Element Type Parameters”

  1. Long Nguyen Avatar
    Long Nguyen

    Hi Jeremy
    How can I access the element content of a family instance. I am working on an addin that automatically pick all the model lines that are contained within the user-selected family instances. Thanks?
    Bests
    Long Nguyen

  2. There are 10 types of people in the world… Those who understand binary and those that don’t…

  3. Dear Keldar,
    :-)
    I like that!
    Thank you!
    Cheers, Jeremy.

  4. Dear Long Nguyen,
    It is simple and the blog presents numerous examples of this.
    You can also look at the Revit SDK ElementViewer sample.
    Basically, simply traverse element, FamilyInstance, geometry, symbol, instance, geometry.
    Cheers, Jeremy.

  5. Long Nguyen Avatar
    Long Nguyen

    Thanks Jeremy,
    Using your hints, I finally managed to retrieve all the model lines in the user-selected family instances. But I now I am facing another issue. My aim is to use these lines for form creation. The NewExtrusionForm method requires a array of references to these lines. However the Reference property of these lines are null (the documentation says that this property is non-null only when the line is obtained directly from an element, while in my case, the line is a geometryCurve contained within a Family Instance object). So how can I get around this.
    I notice that in the Revit GUI the user can use the tab key to manually select these lines and click on the create from button on the ribbon to create the desired form. Basically I am trying to reproduce this process programmatically, because the project we are working on has lots of such lines and the user cannot manually pick all of them by hand (with a lot of tab-key pressings) :)
    Cheers,
    Long

  6. Dear Long Nguyen,
    Thank you for the appreciation. I am glad it helped.
    Did you set ComputeReferences to true when retrieving the family instance geometry?
    If that does not help, and your line comes from the family instance geometry, you may have to recreate a true model line in the current project from it and use that.
    Before you do anything at all, talk with a product usage expert and find out what the correct way is to do this manually in the user interface!
    Cheers, Jeremy.

  7. Long Nguyen Avatar
    Long Nguyen

    Dear Jeremy,
    Thanks for the suggestion. I am giving it a try and will let you know if it works.
    Bests
    Long

  8. Long Nguyen Avatar
    Long Nguyen

    It works great Jeremy !!! This will allow my colleagues and students create lots of interesting geometry with Revit. Many thanks for your tip on ComputeReferences.
    Best
    Long

  9. Dear Long Nguyen,
    Thank you for your appreciation.
    I am very glad I could help and look forward to seeing all the interesting things you come up with.
    Cheers, Jeremy.

Leave a Reply to Long NguyenCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading