BuiltInParameterGroup deprecated in 2024 need help with replacement

BuiltInParameterGroup deprecated in 2024 need help with replacement

rodelWADLJ
Observer Observer
954 Views
1 Reply
Message 1 of 2

BuiltInParameterGroup deprecated in 2024 need help with replacement

rodelWADLJ
Observer
Observer

Hi,

 

Very new with Revit and .NET but have to build this application into the latest version.

 

Full code below:

 

public bool AddNewParameterToWallTypes(UIApplication app, string parameterName, BuiltInParameterGroup paramGroup = BuiltInParameterGroup.INVALID)
{
    var definitionFile = GetSharedParameterFile(app);

    if (definitionFile == null)
        return false;

    // Get the group to which the parameter belongs
    var group = definitionFile.Groups.get_Item("Testing");

    // If the group does not exist, create it
    if (group == null)
    {
        definitionFile.Groups.Create("Testing");
        group = definitionFile.Groups.get_Item("Testing");
    }

    // Get the parameter out of the group
    var parameterDefinition = group.Definitions.get_Item(parameterName);

    // If the parameter does not exist, create it
    if (parameterDefinition == null)
    {
        ExternalDefinitionCreationOptions options;

        if (parameterName == "InstallationGuideline" || parameterName == "DataSheet" || parameterName == "TypicalConstructionDetails" || parameterName == "Literature" || parameterName == "DistributedBy")
            options = new ExternalDefinitionCreationOptions(parameterName, SpecTypeId.String.Url);
        else
            options = new ExternalDefinitionCreationOptions(parameterName, SpecTypeId.String.Text);

        group.Definitions.Create(options);
        parameterDefinition = group.Definitions.get_Item(parameterName);
    }

    // Create a new Binding object with the categories to which the parameter will be bound
    var categories = app.Application.Create.NewCategorySet();

    // use category instead of the string name to get category 
    var wallsCategory = app.ActiveUIDocument.Document.Settings.Categories.get_Item(BuiltInCategory.OST_Walls);
    categories.Insert(wallsCategory);

    var caseTying = app.Application.Create.NewTypeBinding(categories);

    // Add the binding and definition to the document
    var result = app.ActiveUIDocument.Document.ParameterBindings.Insert(parameterDefinition, caseTying, paramGroup);

    return result;
}

 

 

`BuiltInParameterGroup` is not working since we're using 2024. Based on the docs

We've checked the docs https://www.revitapidocs.com/2024/9942b791-2892-0658-303e-abf99675c5a6.htm, we have to use the `GroupTypeId` class instead.

 

We've tried using the `GroupTypeId` but it has an error `GroupTypeId` static types cannot be used as parameters.

AddNewParameterToWallTypes(UIApplication app, string parameterName, GroupTypeId paramGroup = GroupTypeId.INVALID)

 

Another thing we have tried is using the `ForgeTypeId` which didn't give us an error but I don't think it is what we wanted. The reason why I tried `ForgeTypeId` is because on the code below, `paramGroup` is trying to convert it into `Autodesk.Revit.DB.ForgeTypeId`.

var result = app.ActiveUIDocument.Document.ParameterBindings.Insert(parameterDefinition, caseTying, paramGroup);

 

Any help and suggestion is appreciated!

 

Thanks!

0 Likes
Accepted solutions (1)
955 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni
Accepted solution

Here is at least a solution for BuiltInParameterGroup.INVALID:

 

https://thebuildingcoder.typepad.com/blog/2023/11/journal-magic-adjacent-rooms-and-room-boundary.htm...

  

Maybe that will help solve the rest as well.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes