- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!
Solved! Go to Solution.