【Revit API】创建工作集并将element加入工作集中

匿名 (未验证) 提交于 2019-12-02 22:10:10

话不多说,直接上代码!

 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;         }  }

结尾:

进入设计院两周,发现市面上的Revit插件与设计院的需求差距还是很大的,设计院对视图的显示方面的要求较高。一个人在中心从事Revit插件开发压力山大啊,告诉自己慢慢来,能赢!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!