I want to use the Revit API to add project parameters by referencing information in the shared parameter file.
Which API would help? I would be glad to know.
Solved! Go to Solution.
Solved by Mohamed_Arshad. Go to Solution.
こんにちは@Yoshiyuki_Miyauchi さん
Kindly follow below steps to add project parameter using Revit API.
1. Open SharedParameterFile
2. Get Group from SharedParameter File
3. Get Parameter
4. Filter Categories
5. Create Type/ Instance Binding
6. Bind parameter to project
Reference Code
//Revit Document Access
Application app = commandData.Application.Application;
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
//SharedParameter File Path
string path = @"C:\Users\XXXXX\Desktop\TextShared.txt";
//Open SharedParameter File
DefinitionFile defFile = app.OpenSharedParameterFile();
ExternalDefinition parameter = null;
//Get Group
foreach (DefinitionGroup group in defFile.Groups)
{
if (group.Name == "Demo")
{
Definitions extDefinitions = group.Definitions;
//Get Parameter
foreach (ExternalDefinition definition in extDefinitions)
{
if (definition.Name == "Demo Parameter")
{
parameter = definition;
}
}
}
}
//Filter Categories
Categories cat = doc.Settings.Categories;
CategorySet set = new CategorySet();
foreach (Category category in cat)
{
if (category.Name == "Walls")
{
set.Insert(category);
}
}
using (Transaction insert = new Transaction(doc, "add parameter"))
{
insert.Start();
//Create Type Binding
Binding type = app.Create.NewTypeBinding(set);
//Bind Type Parameter
BindingMap map = uiDoc.Document.ParameterBindings;
map.Insert(parameter, type, BuiltInParameterGroup.PG_DATA);
insert.Commit();
}
Reference Links
https://spiderinnet.typepad.com/blog/2011/05/parameter-of-revit-api-31-create-project-parameter.html
Hope this Will Helps 🙂
@Mohamed_Arshad san
Thank you!
That was very helpful.
Can't find what you're looking for? Ask the community or share your knowledge.