Quantcast
Channel: All Revit API Forum posts
Viewing all articles
Browse latest Browse all 67020

Re: Family Types & Shared Parameter Values

$
0
0

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/CmdFamilyParamValue.cs#L32-L82

 

I hope this helps.

 

Best regards,

 

Jeremy


Viewing all articles
Browse latest Browse all 67020

Trending Articles