Family Types & Shared Parameter Values

Family Types & Shared Parameter Values

stephen_harrison
Advocate Advocate
2,441 Views
2 Replies
Message 1 of 3

Family Types & Shared Parameter Values

stephen_harrison
Advocate
Advocate

First thankyou in advance for any help that is provided but this issue has been causing me a problems for days. I am probably missing something very obvious but I just cannot see it!

 

First a little background I am using Revit 2016 and programming in C#.

 

My issue is I have a family (rfa} document in this instance it is a Furniture document in which I have a desk type with shared parameters. Further types of desk with varied size have been created using Family Types => New within the Family Types Dialog.

I can extract the parameters and the values for each of the desk types. However if I wish to change the value of a parameter I can only change the value for the desk type currently visible in the document.

I have tried code such as that below to iterate through the types but this still only works on the desk type currently visible and not the type current within the code.

 

FamilyTypeSet familyTyes = familyManager.Types;FamilyTypeSetIterator familyTypeItor = familyTyes.ForwardIterator();familyTypeItor.Reset();

while (familyTypeItor.MoveNext())

  {

  FamilyParameter familyParam = familyManager.get_Parameter(spNameAmend);

  if (familyParam != null)

    {

    FamilyType familyType = familyTypeItor.Current as FamilyType;

    MessageBox.Show(familyType.Name);

    familyManager.Set(familyParam, 2);

    }

  }

 

What am I missing?

I was also wondering when adding a shared parameter via the API you can use

 

ExternalDefinitionCreationOptions option

 

This allows you to identify a number of binding options but is there an option for setting the parameter as

Reporting and IsDeterminedByFormula ?

 

Any help will be much appreciated

0 Likes
Accepted solutions (2)
2,442 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Stephen,

 

Thank you for your query.

 

The code you show above looks pretty out of date to me.

 

Where is your transaction handling?

 

The possibility to use automatic transactions is obsolete and will disappear in the next major release of Revit.

 

It has been unofficially deprecated for over four years now:

 

http://thebuildingcoder.typepad.com/blog/2012/05/read-only-and-automatic-transaction-modes.html

 

Regarding the issue you are facing, the solution is really simple.

 

The family parameter that you wish to change the value for has a specific value for each of the types defined in the family.

 

You are very correctly iterating over the types.

 

Before you call the Set method to update the parameter value, however, you need to make each one of the types that you visit current so that it is indeed affected by the call.

 

This is achieved by setting the family manager CurrentType property.

 

That is explained in the following discussions by The Building Coder:

 

 

Here is your original sample code, very slightly cleaned up, plus my amended version with a full clean-up plus the call to set the current type:

 

  /// <summary>
  /// Non-working sample code for
  /// http://forums.autodesk.com/t5/revit-api/family-types-amp-shared-parameter-values/m-p/6218767
  /// </summary>
  void SetFamilyParameterValueFails(
    Document doc,
    string paramNameToAmend )
  {
    FamilyManager mgr = doc.FamilyManager;
    FamilyTypeSet familyTypes = mgr.Types;
    FamilyTypeSetIterator familyTypeItor
      = familyTypes.ForwardIterator();
    familyTypeItor.Reset();
    while( familyTypeItor.MoveNext() )
    {
      FamilyParameter familyParam
        = mgr.get_Parameter( paramNameToAmend );

      if( familyParam != null )
      {
        FamilyType familyType = familyTypeItor.Current as FamilyType;
        Debug.Print( familyType.Name );
        mgr.Set( familyParam, 2 );
      }
    }
  }

  /// <summary>
  /// Working sample code for
  /// http://forums.autodesk.com/t5/revit-api/family-types-amp-shared-parameter-values/m-p/6218767
  /// </summary>
  void SetFamilyParameterValueWorks(
    Document doc,
    string paramNameToAmend )
  {
    FamilyManager mgr = doc.FamilyManager;
    FamilyParameter familyParam
      = mgr.get_Parameter( paramNameToAmend );

    if( familyParam != null )
    {
      foreach( FamilyType familyType in mgr.Types )
      {
        Debug.Print( familyType.Name );
        mgr.CurrentType = familyType;
        mgr.Set( familyParam, 2 );
      }
    }
  }

 

I added this code to The Building Coder samples release 2016.0.126.6:

 

https://github.com/jeremytammik/the_building_coder_samples

 

https://github.com/jeremytammik/the_building_coder_samples/releases/tag/2016.0.126.6

 

You can look at the live version of the code right here:

 

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/C...

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 3

stephen_harrison
Advocate
Advocate
Accepted solution
Thank you so much for the concise answer and sample code.
Just what I needed.
0 Likes