VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • C#教程之【Revit API】创建工作集并将element加入工

话不多说,直接上代码!

复制代码
 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插件开发压力山大啊,告诉自己慢慢来,能赢!


相关教程