Adding a Shared Parameter to an RFA File

Back again from my vacation in Avignon.
We had a wonderful drive back up again through the gorges of the

Buëch river

with a beautiful camp near Rosans.
I knew the place from last year, and here are two photos from that visit.
Here is Cornelius at the camp fire in the evening:

Cornelius at the camp fire near Rosans

Here is our camp site in the early morning dew:

Our camp site in the morning dew

We were lucky with the weather, sleeping outside with no roof, preferring the open sky to a tent, and it started raining just after we left but not before.

Looking at old and new subjects to write about, I just discovered a rather overdue issue, a question raised quite a while ago by Arun Shankar of

Reed Business

in a comment on the discussion on

adding a shared parameter to a DWG file
:

Question:
Is it possible to add a shared parameter to an RFA file using the DotNet Revit API?
The example for adding shared parameters to a DWG file does not work for RFA files.
Can you please post some sample code for adding shared parameters to an RFA file?

<!–
First answer, missing the point, as pointed out by Matt Mason:
From: Matt Mason [mailto:matt.mason@avat.com]
Sent: Thursday, June 11, 2009 05:35
To: Jeremy Tammik
Subject: Add Shared Parameter to Family
Jeremy,
Regarding your recent blog post – I think you perhaps misunderstood the original question.
The developer wants to add a shared parameter to an RFA file as a type or instance parameter. This can be done with the FamilyManager.AddParameter() which takes an ExternalDefinition argument.
While it still may be necessary to add it to a project bound to a category, the first step to having the shared parameter in content is to add it to the family itself.
Best Regards,
Matt

Answer:
To address this issue, we first need to understand that shared parameters are always added to some category.
Is there any category that we can use to identify RFA files, or one specific RFA file?
If not, then we will not be able to define any shared parameters for these files.

To explore this issue a bit further, let me discuss a generic approach to analyse the elements added a given action in Revit.
In this case, we will determine what elements are added to the model when an RFA file is loaded, i.e. a new family.

We can explore this as follows using the

Revit API introduction labs

element lister tool implemented in the external command Lab2_1_Elements, which creates a text file listing all Revit database elements and some of their basic properties.
Actually, we have already mentioned this approach in the discussion on

exploring element parameters
.

  • Start off by creating an empty Revit model.
  • List all its elements into a text file RevitElementsBeforeLoadingFamily.txt.
  • Load a new family, for instance the door family Loaded M_Double-Flush.rfa.
  • List the elements again into RevitElementsAfterLoadingFamily.txt.

Now we can determine the elements added by loading the family by comparing the two files using a

diff

tool:


C:tmp > diff
RevitElementsBeforeLoadingFamily.txt
RevitElementsAfterLoadingFamily.txt
2160a2161,2172
> Id=127149; Class=Family; Category=Doors; Name=M_Double-Flush
> Id=127705; Class=Element; Category=?; Name=M_Double-Flush
> Id=127706; Class=FamilySymbol; Category=Doors; Name=1830 x 1981mm
> Id=127707; Class=Element; Category=?; Name=1830 x 1981mm
> Id=127708; Class=FamilySymbol; Category=Doors; Name=1830 x 2083mm
> Id=127709; Class=Element; Category=?; Name=1830 x 2083mm
> Id=127710; Class=FamilySymbol; Category=Doors; Name=1730 x 2134mm
> Id=127711; Class=Element; Category=?; Name=1730 x 2134mm
> Id=127712; Class=FamilySymbol; Category=Doors; Name=1730 x 2032mm
> Id=127713; Class=Element; Category=?; Name=1730 x 2032mm
> Id=127714; Class=FamilySymbol; Category=Doors; Name=1830 x 2134mm
> Id=127715; Class=Element; Category=?; Name=1830 x 2134mm

From this, we see that one family, five family symbols, and five other elements were added.
The family and family symbols all have the category ‘Doors’, the five other elements’ category is undefined.
Therefore, I do not see any way to add a shared parameter to the RFA file or the family itself.
We could add a shared parameter for the Doors category, in which case it would become available on all door family instances as well.
This is demonstrated by the Revit FireRating SDK sample and the Revit API introduction labs 4-1, 4-2 and 4-3, but that is probably not your intention.

–>

Answer:
As pointed out in a private note by

Matt Mason
,
adding a shared parameter to an RFA file is a completely different issue from adding it to a DWG file instance in a project.
In the latter case, we work in the project file and bind a shared parameter to a certain category specific to the inserted DWG file.
For an RFA file, you wish to define the shared parameter in the content, and the first step is to add it to the family itself.

You can add a shared parameter to an RFA file as a type or instance parameter by using the new Family API provided in Revit 2010.
It provides the new method FamilyManager.AddParameter().
Its use is demonstrated by the Revit SDK samples AutoParameter, DWGFamilyCreation and WindowWizard, which are located in the FamilyCreation subdirectory of the Samples folder.
It provides the following overloads:

  • AddParameter(ExternalDefinition, BuiltInParameterGroup, Boolean): Add a new shared parameter to the family.
  • AddParameter(String, BuiltInParameterGroup, Category, Boolean): Add a new family type parameter to control the type of a nested family within another family.
  • AddParameter(String, BuiltInParameterGroup, ParameterType, Boolean): Add a new family parameter with a given name.

To add a shared parameter, you would use the overload taking an ExternalDefinition argument.
DWGFamilyCreation and WindowWizard both only add standard type parameters using the third overload with the fourth isInstance argument set to false, whereas AutoParameter uses both the first and third overloads to create instance, type and shared parameters.

Very many thanks to Matt for pointing this out!


Comments

17 responses to “Adding a Shared Parameter to an RFA File”

  1. Is it possible to add an already existing shared parameter to a RFA from a text file if a GUID has already been created?

  2. Dear Jim,
    What are you trying to achieve? As far as I know, multiple shared parameters with the same name can exist side by side with different GUIDs.
    Cheers, Jeremy.

  3. The AutoParameter sample makes all sharedparameters added instance parameters, while familyparameters get the choice through the isInstance boolean.
    Is it possible to have the option to load sharedparameter as type rather than instance?
    Also the parameter always is placed under the OTHER group, is this my mistake? Why is the parameter group not assigned?
    Thanks
    aj

  4. Dear Alan,
    When shared parameters are added to a project, they apply to one or more entire categories. This always results in instance parameters.
    The parameter group OTHER that you mention corresponds to the BuiltInParameterGroup PG_OTHER.
    You can define the parameter group in which to place a shared parameter if you add it to the family file using the family API, as opposed to creating a shared parameter in the project file. This is described in
    http://thebuildingcoder.typepad.com/blog/2009/06/adding-a-shared-parameter-to-an-rfa-file.html
    Cheers, Jeremy.

  5. Jeremy
    Thank you for taking the time to answer my question. I guess what I am asking is if there is an equivalent BuiltInParameterGroup for shared parameters, so that they can be grouped in anything but OTHER. The reason being is that I would like to schedule these parameters and need them to be shared.
    Thanks again
    aj

  6. Dear Alan,
    As far as I know, shared parameters added to a project file will always end up in the OTHER group.
    I believe that you can change that behaviour if you define them in the family file instead, as mentioned above.
    Cheers, Jeremy.

  7. Jason Bailly Avatar
    Jason Bailly

    “Is it possible to have the option to load sharedparameter as type rather than instance?” – Alan
    I think Alan is still talking about adding shared parameters to a Family (rfa) and not a project (rvt). We have run into the same issue. We want to add shared parameters to a family and have them be type parameters, not instance parameters. How is this accomplished?

  8. Dear Jason,
    Oh, I see what you mean. Thank you very much for the clarification. The answer to that is quite simple. Adding a parameter to a family file is accomplished using one of the three overloads of the FamilyManager AddParameter method. All three take a Boolean argument named isInstance as their last input parameter. The value of that argument determines whether an instance or a type parameter is created.
    You can see this method being used in Lab 2 ‘Create L-Shaped Column’ of the RFA labs provided in the Revit family API webcast materials:
    http://thebuildingcoder.typepad.com/blog/2009/08/the-revit-family-api.html#4
    Cheers, Jeremy.

  9. Hello, Jeremy.
    FamilyManager.AddParameter add parameter to a FamilySymbol or to a FamilyInstance. I need to add parameter directly to a Family. Those parameters I can see in Home Tab – Properties – Family Category and Parameters. Is it possible to add shared parameter to a whole Family which I can get access via document.OwnedFamily.get_Parameter(myOwnParameterGuid)?
    I tried to add parameter to a Family as I did it with ElementType or Instance (Family is Element either) but there are no results. No errors and no results :)
    I did it by following steps
    1) Create ExternalDefinition
    2) Create ElementBinding: var binding = pp.Create.NewInstanceBinding(categories);
    3) Insert Parameter binding res =
    _element.Document.ParameterBindings.Insert(def, binding, BuiltInParameterGroup.PG_IDENTITY_DATA); //here res is true,
    but next line of code
    if (res)
    return _element.get_Parameter(def);
    return false.
    But this code works well with ElementInstance.

  10. I reply myself:) I cannot added my own shared parameter to a Family, but I’ve solve my problem using External Storage.

  11. Dear Victor,
    Well done!
    Here is the reply that I already prepared for you, but am posting too late:
    What are you trying to achieve?
    Remember, shared parameters are basically designed for users. Can you achieve what you want through the user interface? If so, do the same programmatically. If not, forget it.
    One thing you can do is add extensible storage data to an entire family, and then retrieve it when an instance is inserted:
    Define an extensible storage schema and add an entity for it to the family itself, accessed
    through the document OwnerFamily property:
    Entity entity = new Entity( schema );
    entity.Set…( schema.GetField( … ), … );
    doc.OwnerFamily.SetEntity( newEntity );
    Retrieve the stored data from the family by asking the family instance for its family:
    Family family = familyInstance.Symbol.Family;
    Entity entity = family.GetEntity( schema );
    Cheers, Jeremy.

  12. Hello, Jeremy.
    Thanks for answer.
    I’m sorry. When I wrote “External Storage” I meant “Extensible storage”.
    So I solved my problem using Extensible Storage. We have the same thoughts :)
    Regards, Victor.

  13. Dear Victor,
    There is an English saying that goes “great minds think alike” … not so humble, but still :-)
    Cheers, Jeremy.

  14. _app.SharedParametersFilename = filepath;
    DefinitionFile file = _app.OpenSharedParameterFile();
    I am getting error saying “error in reading parameter”

  15. Dear Sir
    I need to add shared parameter using shared parameter file from a particular location…

  16. Hi Jeremy,
    How can I make a almost full proof test that a shared parameter file exists(a project has a sp file assigned) before a method to create a shared parameter bound to the project info is implemented?
    cheers,
    Alex

  17. Dear Alex,
    All I can think of on the spur of the moment is to check the value of the SharedParametersFilename property, and possibly also try to open the file specified and check its contents.
    What are your own experiences with this so far?
    Cheers, Jeremy.

Leave a Reply to Jason BaillyCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading