Parameters versus Properties

In his

comment
on

reading material asset data
,
Alexander Buschmann points
out that this same information can be accessed without retrieving, reading and converting the data directly from the undocumented built-in parameters.

Instead and more comfortably, you can use the following official properties on the appropriate classes:


  Material material = null;
 
  foreach( Material mat in e.Materials )
  {
    material = mat;
    break;
  }
  PropertySetElement pse = doc.GetElement(
    material.StructuralAssetId )
      as PropertySetElement;
 
  StructuralAsset asset = pse.GetStructuralAsset();
 
  double a = asset.WoodBendingStrength;
  double b = asset.WoodParallelCompressionStrength;
  double c = asset.WoodParallelShearStrength;
  double d = asset.WoodPerpendicularCompressionStrength;
  double f = asset.WoodPerpendicularShearStrength;
  // ... and lots of other properties ...

Even though a large and growing number of properties are available through this approach, the “Tension Parallel to Grain” one is actually currently not included in these, so you will indeed still have to use the direct parameter access anyway in this particular case.

Going through parameters is more generic, and most properties available on the classes are also available via parameters.

Parameters can also be used to define a parameter filter for a filtered element collector, so it is always useful to know that they are there and what they mean.

To discover the existence and use of specific parameters, you can use RevitLookup and

BipChecker
to
explore a simple model.
Modify the model interactively through the user interface and observe the effect on the parameters to discover their use and meaning.

He also adds:

For convenience, we use extension methods in our code to do this kind of thing, e.g.


public static class ElementExtensions
{
  public static Material material( this Element e )
  {
    foreach( Material m in e.Materials )
    {
      return m;
    }
    return null;
  }
}

If this class part of an imported namespace, it can be called as:


  Material material2 = e.material();

The compiler will translate that to this:


  Material material3
    = ElementExtensions.material( e );

It is mostly just convenience, but it also improves the readability of the code, since the entire loop above collapses into just this one single property call.

Many thanks to Alexander for pointing this out!

Here are some pointers to other extension methods that we discussed in the past:

Show Viewport Extension Line or Label

Alexander also pointed out some other useful parameter to be aware of on the ViewType class in his

comment
on

changing the viewport type
,
and my colleague Joe Ye just ran into a case dealing with the very same issue:

Question: We can change the length of the view title line:

View title line

For that we have to go to edit type and check the show extension line toggle:

View title line check box

It is possible to achieve this using the API?

Answer: Yes, you can set that check box via the API as well.
Here is the process:

  1. Get the view type object.
  2. Get the parameter that represents the “Show Extension Line”.
  3. Change the parameter value.

Here is an example of performing these three steps:


  ElementId typeId = viewport.GetTypeId();
 
  ViewType viewtype = doc.GetElement( typeId )
    as ViewType;
 
  Parameter withLine = viewtype.get_Parameter(
    BuiltInParameter
      .VIEWPORT_ATTR_SHOW_EXTENSION_LINE );
 
  withLine.Set( 0 ); // No Line
  withLine.Set( 1 ); // Has Line

Alexander also points out that the built-in parameter VIEWPORT_ATTR_SHOW_LABEL affects the view label in a similar manner.


Comments

3 responses to “Parameters versus Properties”

  1. Hi Jeremy,
    some notices:
    I found out that there could be the case that Element.Level property is null while a Level parameter contains a valid value.
    Also, think of the fact that the BuiltInParameter (for displaying the Level) may be depending on Element’s type and/or Category.
    Type Area’s level is represented by BIP.ROOM_LEVEL_ID, for example…
    “ROOM” !? It’s the same with the BIP.DOOR_COST parameter (which can be found by elements which aren’t doors at all).
    Cheers,
    Rudolf

  2. Aleksey Avatar
    Aleksey

    Hi Jeremy,
    I have created a family of elements and asked them the dimension values (width, hight, lenght and volume).
    https://docs.google.com/file/d/0B-mguLjIXRoQSXRvQ3o3TGQ2Sjg/edit?usp=sharing
    They are displayed only in the type properties.
    How do I get these values? (C#, Revit 2011)

  3. Dear Aleksey,
    To query the type properties instead of the instance ones, retrieve the parameter from the type element instead of the instance element.
    This is demonstrated in numerous places, e.g. by the BipChecker:
    http://thebuildingcoder.typepad.com/blog/2013/01/built-in-parameter-enumeration-duplicates-and-bipchecker-update.html
    Cheers, Jeremy.

Leave a Reply to Jeremy TammikCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading