Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Create a new parameter for all family instances of a Family .NET C#

rita.aguiar
Advocate
Advocate

Create a new parameter for all family instances of a Family .NET C#

rita.aguiar
Advocate
Advocate

Hello

I am trying to create a plugin which creates a new parameter under the Parameter Group 'Identity Data' of a specific Family.

I have done this before but I created a new parameter for all families under the Plates Category and so I adapted its script.

First, I am trying to create the parameter named "Marca" on all instances of the Mechanical Equipment Category (later I will try to do so just for the Family Type 'TPF-Pump').

However, I get the following error, where the Definition 'FamilyParamDef' became null.

Any ideas on why this is happening?

Any help would be appretiated.

 

The code was based on the Building Coder Sample

https://forums.autodesk.com/t5/revit-api-forum/shared-parameter-to-assign-to-elements/td-p/8455214

//test for one parameter
string paramName = "Marca";

// cache application handle
Autodesk.Revit.ApplicationServices.Application revitApp = commandData.Application.Application;

// open shared parameter file
DefinitionFile parafile = revitApp.OpenSharedParameterFile();

// get a group DefinitionGroup apiGroup = parafile.Groups.get_Item("Identity Data"); // get ParamName Definition FamilyParamDef = apiGroup.Definitions.get_Item(paramName); // get Mechanical Equipment category Category FamilyCat = commandData.Application.ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_MechanicalEquipment); CategorySet categories = revitApp.Create.NewCategorySet(); categories.Insert(FamilyCat); // insert the new parameter InstanceBinding binding = revitApp.Create.NewInstanceBinding(categories); commandData.Application.ActiveUIDocument.Document.ParameterBindings.Insert(FamilyParamDef, binding, BuiltInParameterGroup.PG_DATA);

 

CreateParameters.png

0 Likes
Reply
Accepted solutions (1)
980 Views
2 Replies
Replies (2)

rita.aguiar
Advocate
Advocate
0 Likes

rita.aguiar
Advocate
Advocate
Accepted solution

I just realized that to add the parameter to the Family, it should already be defined in the SharedParamater file... This is not ideal at all. Also, the creation of the parameter apparrently needs to be done inside a transaction mode.CreateParameters2.png

 

 

 

0 Likes