【Revit API】建立工做集並將element加入工做集中

話很少說,直接上代碼!ui

 public class WorkSetHelper
 {
        public void AddElementsToWorkSet(Document doc, List<Element> elements)
        {
            if (doc.IsWorkshared == true)
            {
                var workset = GetWorkset(doc);
                if (workset != null)
                {
                    var worksetID = workset.Id.IntegerValue;
                    using (Transaction tran = new Transaction(doc, "[ToolSet] Add Elemens To WorkSet"))
                    {
                        tran.Start();
                        foreach (var ele in elements)
                        {
                            Parameter wsparam = ele.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
                            if (wsparam != null)
                            {
                                wsparam.Set(worksetID);
                            }                          
                        }
                        tran.Commit();
                    }                   
                }               
            }
        }

        public Workset GetWorkset(Document doc)
        {
            Workset newWorkset = null;
            // Worksets can only be created in a document with worksharing enabled
            if (doc.IsWorkshared)
            {
                string worksetName = "WorkSetName";
                // Workset name must not be in use by another workset
                if (WorksetTable.IsWorksetNameUnique(doc, worksetName))
                {
                    using (Transaction tran = new Transaction(doc, "[ToolSet] Create Work Set For ToolSet"))
                    {
                        tran.Start();
                        newWorkset = Workset.Create(doc, worksetName);
                        tran.Commit();
                    }
                }
                else
                {
                    IList<Workset> worksetList = new FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset).ToWorksets();
                    foreach (Workset workset in worksetList)
                    {
                        if (workset.Name.Contains(worksetName))
                        {
                            return workset;
                        }
                    }
                }
            }
            return newWorkset;
        }
 }

 

結尾:spa

        進入設計院兩週,發現市面上的Revit插件與設計院的需求差距仍是很大的,設計院對視圖的顯示方面的要求較高。一我的在中心從事Revit插件開發壓力山大啊,告訴本身慢慢來,能贏!插件

相關文章
相關標籤/搜索