Revit二开--Revit工作集的操作

Revit二开–Revit工作集的操作

做revit开发的过程中我们要对revit工作集进行操作的时候我们要用到一个类 FilteredWorksetCollector
用这个类我们可以过滤到所有的工作集,然后根据工作集的分类 枚举 WorksetKind 来取得想要的工作集类别集合。

以下代码演示如何取得用户创建的工作集。
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    [Journaling(JournalingMode.UsingCommandData)]

    class WorkSetTest : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            Selection sel = uidoc.Selection;
            View acview = uidoc.ActiveView;

            //var worksettable = doc.GetWorksetTable();
            //创建工作集过滤器集合
            FilteredWorksetCollector setcollector = new FilteredWorksetCollector(doc);
            //根据工作集种类取得 用户创建的工作集 (WorksetKind.UserWorkset)
            setcollector.OfKind(WorksetKind.UserWorkset);

            foreach (Workset workset in setcollector)
            {
                MessageBox.Show(workset.Name);
            }

            MessageBox.Show(setcollector.Count().ToString());
            return Result.Succeeded;
        }
    }

以上代码我们获取了用户创建的工作集,如果想获取去他类别的工作集,我们只需要改变枚举值为目标枚举值即可
在这里插入图片描述
这四种枚举值分别 对应

    //
    // 摘要:
    //     Indicates one of the standard kinds of workset (as available in the UI).
    public enum WorksetKind
    {
        //
        // 摘要:
        //     Any workset which is not one of the standard types included in this enum.
        OtherWorkset = 0,
        //
        // 摘要:族
        //     Workset containing a family.
        FamilyWorkset = 1,
        //
        // 摘要:视图
        //     Workset containing a view.
        ViewWorkset = 2,
        //
        // 摘要:项目标准
        //     Workset containing a standard.
        StandardWorkset = 3,
        //
        // 摘要:用户创建
        //     Workset defined by users, including the two default worksets created by Revit
        UserWorkset = 4
    }


在这里插入图片描述

唐僧课堂BIM开发

发布了47 篇原创文章 · 获赞 51 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/binbinstrong/article/details/90436661
今日推荐