【转】Revit二次开发——利用共享参数添加项目信息参数

using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.Attributes;
using System.IO;
using System.Reflection;
using Autodesk.Revit.DB.Events;
 
 
namespace CreatSharedParams
{
    [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class Class8 : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
 
            Application RevitApp = uidoc.Application.Application;
 
            Transaction trans = new Transaction(doc, "CreatSharedParams");
            trans.Start();
 
            RevitApp.SharedParametersFilename = @"F:\test.txt"; // 请设置到不用管理员权限的地方
 
            DefinitionFile definitionFile = RevitApp.OpenSharedParameterFile();
 
            DefinitionGroup group = definitionFile.Groups.Create("GroupX");  
 
            ExternalDefinitionCreationOptions edco = new ExternalDefinitionCreationOptions("参数测试文本", ParameterType.Text);
 
            Definition definition = group.Definitions.Create(edco); 
 
            CategorySet categories = new CategorySet();
            categories.Insert(doc.Settings.Categories.get_Item(BuiltInCategory.OST_ProjectInformation));
          
            Binding binding = new InstanceBinding(categories);  
 
            doc.ParameterBindings.Insert(definition, binding);  
 
            trans.Commit();
            return Result.Succeeded;
        }

 

posted on 2020-12-03 10:07  梦琪小生  阅读(649)  评论(0编辑  收藏  举报

导航