Get and Set Family Category and Parameters

I am receiving a lot of questions about parameters in family documents, so I will be posting several solutions in this area in the next few days.
The first one is short and simple and suited for a rapid Saturday post.
There is so much news coming that I do want to cram it in right away.
This is a question from Jose Fandos of

Andekan LLC
:

Question:
How can we get and set the family category and the family parameters seen in the “Family Category and Parameters” Revit dialogue box?
This dialogue can be displayed by selecting Create > Category and Parameters in the family editor:

Family Category and Parameters dialogue

The parameters include the OmniClass number, for instance.
We are not looking for the type or symbol parameters, and we need this access from the family editor, not from the project editor.

Answer:
I used the RvtMgdDbg tool to explore a family file to answer your query.
Using that, I can step into RvtMgdDbg > Snoop Application… > Application > Active Document > Owner Family > Parameters to see the family parameters, including the OmniClass number with the built-in parameter enumeration value OMNICLASS_CODE:

Snoop OmniClass number

The family category is also available as a property on this owner family object, but it is read-only.

Here is the external command Execute method that I implemented to demonstrate read access to both of these properties and write access to the OmniClass number:


BuiltInParameter _bip = BuiltInParameter.OMNICLASS_CODE;
 
public IExternalCommand.Result Execute(
  ExternalCommandData commandData,
  ref string message,
  ElementSet elements )
{
  Application app = commandData.Application;
  Document doc = app.ActiveDocument;
 
  if( !doc.IsFamilyDocument )
  {
    message
      = "Please run this command in a family document.";
  }
  else
  {
    Family f = doc.OwnerFamily;
    Category c = f.FamilyCategory;
    Parameter p = f.get_Parameter( _bip );
 
    Debug.Print(
      "Category '{0}', OmniClassNumber {1}",
      c.Name, p.AsString() );
 
    p.Set( "Jeremy" );
 
    Debug.Print( "Modified OmniClassNumber {0}",
      f.get_Parameter( _bip ).AsString() );
  }
  return IExternalCommand.Result.Failed;
}

Note that I am returning Failed from the Execute method, so the transaction that Revit is managing for my command will be aborted, so the changes I made will not actually be committed.

Next week I plan to discuss work-arounds for the challenges surrounding shared parameters in family files, so stay tuned.
Happy weekend to all!


Comments

4 responses to “Get and Set Family Category and Parameters”

  1. Dorien Elleboog Avatar
    Dorien Elleboog

    Dear Jeremy,
    I have a similar question:
    ‘Part Type’ is a property (form a Pipe Fitting) in a family document, like ‘OmniClass Number’ is.
    How do I get access to it from my main document?
    My main document contains code to calculate the radius of pipes & fittings in a Sanitary Symstem. There’s a difference in PipeFittings (elbows, cross, transition,… = ‘Part Type’), with causes the code to change for some fittings. I want to filter them with the ‘Part Type’- property.
    Thnx anyway,
    Dorien

  2. Dear Dorien,
    Thank you for the mail and sorry for not picking this up earlier. There is a PartType property on the MechanicalFitting class, but other for elements I do not believe that there is any access to this property except the view that you mention when looking at it in the family document, so you will have to find some other way to identify the different types of fittings. Sorry about that as well.
    Cheers, Jeremy.

  3. Hello Jeremy dude,
    Is this possible to set family category for family document. (not part type).

  4. Dear Jai Ho dude,
    Actually, you are in luck: yes, it is.
    Please refer to the following little note in
    http://thebuildingcoder.typepad.com/blog/2013/04/whats-new-in-the-revit-2014-api.html
    Families & content
    Family category
    The property

    FamilyBase.FamilyCategory

    can now be set. This allows the category of an family being edited to be changed.
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading