Exemple #1
0
 private void FindWorkset(ParameterProperties pp, bool isFirstParam)
 {
     try
     {
         foreach (int worksetId in pp.IntValues)
         {
             if (worksets.ContainsKey(worksetId))
             {
                 Workset workset = worksets[worksetId];
                 if (isFirstParam)
                 {
                     cmbValue1.Items.Add(workset.Name);
                 }
                 else
                 {
                     cmbValue2.Items.Add(workset.Name);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         string message = ex.Message;
     }
 }
Exemple #2
0
        protected override void Handle(StartProjectTaskCommand request)
        {
            if (TaskRecorder.HasActiveTask)
            {
                DuplicateTaskValidator taskValidator = new DuplicateProjectTaskValidator(TaskRecorder.ActiveTask,
                                                                                         request.ProjectDto.ID, request.ProjectStageDto.ID, request.WorksetDto.ID,
                                                                                         request.IsAddCost, request.IsMistake);
                taskValidator.ValidateDuplicate();
            }

            if (TaskService.AskBeforeStartNewTaskResult() == DialogResult.No)
            {
                return;
            }

            DateTime currentTime = Database.GetCurrentTime();

            if (TaskRecorder.HasActiveTask)
            {
                TaskRepository.Finish(TaskRecorder.ActiveTask, currentTime);
                TaskRecorder.StopActiveTask(currentTime);
            }

            Project      project        = ProjectRepository.Load(request.ProjectDto.ID);
            ProjectStage projectStage   = ProjectStageRepository.Load(request.ProjectStageDto.ID);
            Workset      workset        = WorksetRepository.Load(request.WorksetDto.ID);
            ProjectTask  newProjectTask = TaskFactory.CreateProjectTask(TaskRepository.NextIdentity(), project, projectStage,
                                                                        workset, request.IsAddCost, request.IsMistake);

            TaskRepository.Save(newProjectTask, currentTime);
            TaskRecorder.StartNewTask(newProjectTask, currentTime);
            WorkTimer.Start();
        }
Exemple #3
0
            public bool IsUserWorksetElement(ElementId elId)
            {
                Element el = this.document.GetElement(elId);
                Workset ws = this.document.GetWorksetTable().GetWorkset(el.WorksetId);

                return(ws.Kind == WorksetKind.UserWorkset);
            }
Exemple #4
0
        private static Workset GetWorkSet(Document doc)
        {
            Workset workSet = null;

            if (doc.IsWorkshared)
            {
                string workSetName = "WorkSetName";
                if (WorksetTable.IsWorksetNameUnique(doc, workSetName))
                {
                    using (Transaction tran = new Transaction(doc, "[ToolSet] Create Work Set For ToolSet"))
                    {
                        tran.Start();
                        workSet = Workset.Create(doc, workSetName);
                        tran.Commit();
                    }
                }
                else
                {
                    IList <Workset> list = new FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset).ToWorksets();
                    foreach (var item in list)
                    {
                        if (item.Name.Contains(workSetName))
                        {
                            return(item);
                        }
                    }
                }
            }
            return(workSet);
        }
        public static void TestSort()
        {
            Workset workset1 = new Workset {
                masterItemID = "6b9c0ebf7180f7184884577a4d299937", currentItemID = "c5082c2ea95e51be0449ab5a5c869557", immediateMasterItemID = "028993c3c6206661398141ec2128c786"
            };
            Workset workset2 = new Workset {
                masterItemID = "6b9c0ebf7180f7184884577a4d299937", currentItemID = "6b9c0ebf7180f7184884577a4d299937", immediateMasterItemID = null
            };
            Workset workset3 = new Workset {
                masterItemID = "6b9c0ebf7180f7184884577a4d299937", currentItemID = "028993c3c6206661398141ec2128c786", immediateMasterItemID = "6b9c0ebf7180f7184884577a4d299937"
            };

            //Workset workset4 = new Workset { masterItemID = "xyz", currentItemID = "ghi", immediateMasterItemID = "def" };
            //Workset workset7 = new Workset { masterItemID = "xy", currentItemID = "ghi", immediateMasterItemID = "abc" };
            //Workset workset5 = new Workset { masterItemID = "xy", currentItemID = "xy", immediateMasterItemID = null };
            //Workset workset6 = new Workset { masterItemID = "xy", currentItemID = "abc", immediateMasterItemID = "xy" };



            Workset[] worksets = new List <Workset> {
                workset1, workset2, workset3
            }.ToArray();

            Workset[] sortedWorkset = new Workset[worksets.Length];

            int count = worksets.Length;

            InsertionSort(ref worksets);

            foreach (var item in worksets)
            {
                Console.WriteLine(item);
            }
        }
Exemple #6
0
        public static void SetWorkset(Element elem, Workset w)
        {
            Parameter wsparam = elem.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);

            if (wsparam == null)
            {
                return;
            }
            if (wsparam.IsReadOnly)
            {
                return;
            }

            bool elemNonGroup = (elem.GroupId == null) || (elem.GroupId == ElementId.InvalidElementId);

            if (elemNonGroup)
            {
                wsparam.Set(w.Id.IntegerValue);
            }
            else
            {
                Group gr = elem.Document.GetElement(elem.GroupId) as Group;
                SetWorkset(gr, w);
            }
        }
Exemple #7
0
        public static Workset GetOrCreateWorkset(Document doc, string worksetName)
        {
            IList <Workset> userWorksets = new FilteredWorksetCollector(doc)
                                           .OfKind(WorksetKind.UserWorkset)
                                           .ToWorksets();

            bool checkNotExists = WorksetTable.IsWorksetNameUnique(doc, worksetName);

            if (!checkNotExists)
            {
                Debug.WriteLine("Workset exists: " + worksetName);
                Workset wset = new FilteredWorksetCollector(doc)
                               .OfKind(WorksetKind.UserWorkset)
                               .ToWorksets()
                               .Where(w => w.Name == worksetName)
                               .First();
                return(wset);
            }
            else
            {
                Debug.WriteLine("Create workset: " + worksetName);
                Workset wset = Workset.Create(doc, worksetName);
                return(wset);
            }
        }
        private static FilteredElementCollector WorksetElements(Document doc, Workset workset)
        {
            FilteredElementCollector elementCollector     = new FilteredElementCollector(doc).OfClass(typeof(Family));
            ElementWorksetFilter     elementWorksetFilter = new ElementWorksetFilter(workset.Id, false);

            return(elementCollector.WherePasses(elementWorksetFilter));
        }
Exemple #9
0
        public static void SetWorkset(Element elem, Workset w)
        {
            Debug.WriteLine("Set workset: " + w.Name + " for elem id " + elem.Id.IntegerValue);
            Parameter wsparam = elem.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);

            if (wsparam == null)
            {
                return;
            }
            if (wsparam.IsReadOnly)
            {
                return;
            }

            bool elemNonGroup = (elem.GroupId == null) || (elem.GroupId == ElementId.InvalidElementId);

            if (elemNonGroup)
            {
                wsparam.Set(w.Id.IntegerValue);
                Debug.WriteLine("Set workset success");
            }
            else
            {
                Group gr = elem.Document.GetElement(elem.GroupId) as Group;
                SetWorkset(gr, w);
                Debug.WriteLine("Elem is in group; set workset for group: " + gr.Name);
            }
        }
Exemple #10
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument     uidoc       = commandData.Application.ActiveUIDocument;
            Document       doc         = uidoc.Document;
            Workset        workset     = null;
            List <Element> elementList = new List <Element>();
            // 让用户输入工作集名称 添加至list 批量生成工作集
            List <string> newWorkList = new List <string> {
                "(01-1F-建筑-墙)", "02-1F-结构-墙", "03-1F-建筑-门", "04-1F-建筑-窗", "05-1F-建筑-柱"
            };

            if (!doc.IsWorkshared)
            {
                message = "该项目不是中心文件。";
                return(Result.Failed);
            }

            foreach (string newworksetName in newWorkList)
            {
                workset = CreateWorksets(doc, newworksetName);
            }

            TaskDialog.Show("Revit", "工作集创建成功");
            //BuiltInCategory builtInCategory = BuiltInCategory.OST_Doors;
            //Type type = typeof(FamilyInstance);
            //string levelName = "Level 1";
            //Level level = GetLevel(doc, levelName);
            //elementList = FilterElement(doc, builtInCategory, type, level);
            //AddElementToWorkset(doc, workset, elementList);


            return(Result.Succeeded);
        }
Exemple #11
0
        /// <summary>
        /// 创建工作集
        /// </summary>
        /// <param name="doc">当前文档</param>
        /// <param name="worksetName">输入工作集名称</param>
        /// <returns>新的工作集</returns>
        public Workset CreateWorksets(Document doc, string worksetName)
        {
            Workset newWorksets = null;

            if (WorksetTable.IsWorksetNameUnique(doc, worksetName))
            {
                using (Transaction trans = new Transaction(doc, "创建工作集"))
                {
                    trans.Start();
                    newWorksets = Workset.Create(doc, worksetName);
                    trans.Commit();
                }
            }
            //判定是否有重名的工作集
            else
            {
                FilteredWorksetCollector worksetCollector = new FilteredWorksetCollector(doc);
                IList <Workset>          worksetsList     = worksetCollector.OfKind(WorksetKind.UserWorkset).ToWorksets();
                foreach (Workset workset in worksetsList)
                {
                    if (workset.Name.Contains(worksetName))
                    {
                        return(workset);
                    }
                }
            }
            return(newWorksets);
        }
Exemple #12
0
        private void BtnCreate_Click(object sender, EventArgs e)
        {
            // check if at least one item is selected
            if (LsvWorksets.CheckedItems.Count == 0)
            {
                UI.Info.Form_Info1.infoMsgMain = "Selection";
                UI.Info.Form_Info1.infoMsgBody = "Select one or more worksets from the list.";
                using (UI.Info.Form_Info1 thisForm = new Info.Form_Info1())
                {
                    thisForm.ShowDialog();
                }
            }
            else
            {
                // collect selected worksets
                List <string> selectedWorksets = new List <string>();
                foreach (ListViewItem item in LsvWorksets.CheckedItems)
                {
                    selectedWorksets.Add(item.Text);
                }

                // check if workset name is in use
                usedNames = GetUsedNames(m_doc, selectedWorksets);
                if (usedNames.Any())
                {
                    using (UI.Info.Form_Warning thisForm = new UI.Info.Form_Warning())
                    {
                        thisForm.ShowDialog();
                    }
                }
                // proceed if workset names are unique
                else
                {
                    using (TransactionGroup tg = new TransactionGroup(m_doc, "Transfer Worksets"))
                    {
                        tg.Start();
                        createdWorksets.Clear(); // clear results list for when running the command more than once.
                        foreach (string WorksetName in selectedWorksets)
                        {
                            using (Transaction t = new Transaction(m_doc, "Single Transaction"))
                            {
                                t.Start();
                                Workset newWorkset = null;
                                newWorkset = Workset.Create(m_doc, WorksetName);
                                createdWorksets.Add(WorksetName);
                                t.Commit();
                            }
                        }
                        tg.Assimilate();
                    }
                    // show Results Form
                    using (UI.Info.Form_Results thisForm = new Info.Form_Results())
                    {
                        thisForm.ShowDialog();
                    }
                    DialogResult = DialogResult.OK;
                }
            }
        }
        public static Workset GetActiveWorkset(Document doc)
        {
            WorksetTable table    = doc.GetWorksetTable();
            WorksetId    activeId = table.GetActiveWorksetId();
            Workset      workset  = table.GetWorkset(activeId);

            return(workset);
        }
 public ItemInfo(Workset ws, MapType mType)
 {
     WorksetItem   = ws;
     ItemName      = WorksetItem.Name;
     WorksetItemId = WorksetItem.Id;
     ItemId        = WorksetItemId.IntegerValue;
     MapTypeEnum   = mType;
 }
Exemple #15
0
        /// <summary>
        /// Adds the workset.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="gridLvl"></param>
        /// <param name="worksetName"></param>
        /// <returns></returns>
        public static Workset AddWorkset(this Document doc, string gridLvl, string worksetName)
        {
            if (doc.IsWorkshared)
            {
                doc.EnableWorksharing(gridLvl, worksetName);
            }

            return(Workset.Create(doc, worksetName));
        }
Exemple #16
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            uiApp = commandData.Application;
            uiDoc = commandData.Application.ActiveUIDocument;
            dbDoc = commandData.Application.ActiveUIDocument.Document;

            //don't run the command if the project isn't workshared
            if (!dbDoc.IsWorkshared)
            {
                TaskDialog.Show("Match Workset", "This project is not workshared");
                return(Result.Failed);
            }

            ElementSet selElements = uiDoc.Selection.Elements;

            //don't run the command if nothing is selected
            if (0 == selElements.Size)
            {
                TaskDialog.Show("Match Workset", "No assignable elements selected");
                return(Result.Failed);
            }

            Reference target;

            try
            {
                target = uiDoc.Selection.PickObject(ObjectType.Element, new ValidTargetFilter(), "Pick an element on the target workset");
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                return(Result.Cancelled);
            }

            //retrieve the Workset of the target Reference
            Workset targetWs = dbDoc.GetWorksetTable().GetWorkset(dbDoc.GetElement(target.ElementId).WorksetId);

            using (Transaction t = new Transaction(dbDoc, "Match Workset"))
            {
                t.Start();

                foreach (Element e in selElements)
                {
                    Parameter wsParam = e.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
                    if (!wsParam.IsReadOnly)
                    {
                        wsParam.Set(targetWs.Id.IntegerValue);
                    }
                }

                t.Commit();
            }

            return(Result.Succeeded);
        }
Exemple #17
0
        private BaseTask GetActiveProjectTask()
        {
            var project      = new Project(1, "TestName", ProjectType.Engineer);
            var projectStage = new ProjectStage(1, "TestName");
            var workset      = new Workset(1, new List <Activity>()
            {
                new Activity(1, "TestName")
            });

            return(new ProjectTask(1, project, DateTime.Now, DateTime.Now, projectStage, workset, false, false));
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (selectedWorksetNames.Count == 0)
     {
         TaskDialog.Show("Error", "No worksets selected.");
         return;
     }
     // Document doc = extCommandData.Application.ActiveUIDocument.Document;
     using (Transaction t = new Transaction(doc, "Making Worksets"))
     {
         try
         {
             t.Start();
             // Workset workset1 = new FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset).Where(w => w.Name == "Workset1").FirstOrDefault();
             // WorksetId workset1Id = workset1?.Id;
             for (int i = 0; i < selectedWorksetNames.Count; i++)
             {
                 if (WorksetTable.IsWorksetNameUnique(doc, selectedWorksetNames[i].ToString()))
                 {
                     /*
                      * if (i == 0 && workset1Id != null)
                      * {
                      *  WorksetTable.RenameWorkset(doc, workset1Id, selectedWorksetNames[i].ToString());
                      * }
                      * else
                      * {
                      *  Workset.Create(doc, selectedWorksetNames[i].ToString());
                      * }
                      */
                     Workset.Create(doc, selectedWorksetNames[i].ToString());
                 }
                 else
                 {
                     TaskDialog.Show("Error", $"Duplicate workset name already exists in project: {selectedWorksetNames[i]}");
                 }
             }
             t.Commit();
             TaskDialog.Show("Success", $"{selectedWorksetNames.Count} worksets created.");
         }
         catch (Exception error)
         {
             t.RollBack();
             TaskDialog.Show("Error", error.ToString());
         }
     }
     this.Close();
 }
Exemple #19
0
 private void createWorksets(Document NewDoc, string templateType)
 {
     using (Transaction tx = new Transaction(NewDoc))
     {
         tx.Start("CreateWorkset");
         Workset.Create(NewDoc, "ELEC - Link");
         Workset.Create(NewDoc, "MECH - Link");
         Workset.Create(NewDoc, "MEP - Link");
         Workset.Create(NewDoc, "PLUMB - Link");
         Workset.Create(NewDoc, "STRUCT - Link");
         if (templateType == "INTERIOR")
         {
             Workset.Create(NewDoc, "CORE & SHELL - Link");
         }
         tx.Commit();
     }
 }
Exemple #20
0
        public static IEnumerable <Revit.Elements.Element> AllElementsByWorkset(Workset workset)
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;

            IList <Autodesk.Revit.DB.Element> elements = new FilteredElementCollector(doc)
                                                         .WherePasses(new ElementWorksetFilter(workset.Id))
                                                         .ToElements();

            var outputData = new List <Revit.Elements.Element>();

            foreach (Autodesk.Revit.DB.Element elem in elements)
            {
                outputData.Add(elem.ToDSType(true));
            }

            return(outputData);
        }
 public static void ApplyWorksetModifications(Document doc, List <WorksetParameter> worksets, ref TransactionLog log)
 {
     using (Transaction t = new Transaction(doc))
     {
         if (t.Start("Add Worksets to Model.") == TransactionStatus.Started)
         {
             foreach (var w in worksets)
             {
                 if (w.IsModified)
                 {
                     if (w.IsExisting && w.Id >= 0)
                     {
                         if (WorksetTable.IsWorksetNameUnique(doc, w.Name))
                         {
                             WorksetTable.RenameWorkset(doc, new WorksetId(w.Id), w.Name);
                         }
                         var defaultVisibilitySettings = WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(doc);
                         defaultVisibilitySettings.SetWorksetVisibility(new WorksetId(w.Id), w.VisibleInAllViews);
                         log.AddSuccess(w.ToString());
                     }
                     else
                     {
                         Workset newWorkset = null;
                         if (WorksetTable.IsWorksetNameUnique(doc, w.Name))
                         {
                             newWorkset = Workset.Create(doc, w.Name);
                         }
                         else
                         {
                             log.AddFailure(w.ToString());
                             continue;
                         }
                         if (newWorkset != null)
                         {
                             var defaultVisibilitySettings = WorksetDefaultVisibilitySettings.GetWorksetDefaultVisibilitySettings(doc);
                             defaultVisibilitySettings.SetWorksetVisibility(newWorkset.Id, w.VisibleInAllViews);
                             log.AddSuccess(w.ToString());
                         }
                     }
                 }
             }
             t.Commit();
         }
     }
 }
Exemple #22
0
        public ItemInfo(object obj, ViewBy type)
        {
            itemObj  = obj;
            itemType = type;
            switch (type)
            {
            case ViewBy.Workset:
                Workset workset = obj as Workset;
                if (null != workset)
                {
                    itemName = workset.Name;
                    itemId   = workset.Id.IntegerValue;
                }
                break;

            case ViewBy.Phase:
                Phase phase = obj as Phase;
                if (null != phase)
                {
                    itemName = phase.Name;
                    itemId   = phase.Id.IntegerValue;
                }
                break;

            case ViewBy.DesignOption:
                DesignOption designOption = obj as DesignOption;
                if (null != designOption)
                {
                    itemName = designOption.Name;
                    itemId   = designOption.Id.IntegerValue;
                }
                break;

            case ViewBy.Link:
                RevitLinkType linktype = obj as RevitLinkType;
                if (null != linktype)
                {
                    itemName = linktype.Name;
                    itemId   = linktype.Id.IntegerValue;
                }
                break;
            }
        }
Exemple #23
0
        /// <summary>
        /// 创建工作集
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public Workset CreateWorkset(Document doc)
        {
            Workset workset = null;

            if (doc.IsWorkshared)
            {
                string worksetName = "New Workset";
                if (WorksetTable.IsWorksetNameUnique(doc, worksetName))
                {
                    using (Transaction worksetTransaction = new Transaction(doc, "Set preview view id"))
                    {
                        worksetTransaction.Start();
                        workset = Workset.Create(doc, worksetName);
                        worksetTransaction.Commit();
                    }
                }
            }
            return(workset);
        }
Exemple #24
0
        private Workset CreateWorkset(Document document)
        {
            Workset newWorkset = null;

            // Worksets can only be created in a document with worksharing enabled
            if (document.IsWorkshared)
            {
                string worksetName  = "Workset4";
                string worksetName1 = "Workset5";
                string worksetName2 = "Workset6";
                // Workset name must not be in use by another workset
                if (WorksetTable.IsWorksetNameUnique(document, worksetName))
                {
                    using (Transaction worksetTransaction = new Transaction(document, "Set preview view id"))
                    {
                        worksetTransaction.Start();
                        newWorkset = Workset.Create(document, worksetName);
                        worksetTransaction.Commit();
                    }
                }
                if (WorksetTable.IsWorksetNameUnique(document, worksetName1))
                {
                    using (Transaction worksetTransaction = new Transaction(document, "Set preview view id"))
                    {
                        worksetTransaction.Start();
                        newWorkset = Workset.Create(document, worksetName1);
                        worksetTransaction.Commit();
                    }
                }
                if (WorksetTable.IsWorksetNameUnique(document, worksetName2))
                {
                    using (Transaction worksetTransaction = new Transaction(document, "Set preview view id"))
                    {
                        worksetTransaction.Start();
                        newWorkset = Workset.Create(document, worksetName2);
                        worksetTransaction.Commit();
                    }
                }
            }

            return(newWorkset);
        }
        static void InsertionSort(ref Workset[] worksets)
        {
            int i, j;

            for (i = 1; i < worksets.Length; i++)
            {
                Workset key = worksets[i];
                j = i - 1;

                /* Move elements of arr[0..i-1], that are
                 * greater than key, to one position ahead
                 * of their current position */
                while (j >= 0 && worksets[j].currentItemID == key.immediateMasterItemID)
                {
                    worksets[j + 1] = worksets[j];
                    j = j - 1;
                }
                worksets[j + 1] = key;
            }
        } // end insertionSort()
Exemple #26
0
        public Workset GetWorkset(Document doc)
        {
            IList <Workset> userWorksets = new FilteredWorksetCollector(doc)
                                           .OfKind(WorksetKind.UserWorkset)
                                           .ToWorksets();

            bool checkNotExists = WorksetTable.IsWorksetNameUnique(doc, WorksetName);

            if (!checkNotExists)
            {
                Workset wset = new FilteredWorksetCollector(doc)
                               .OfKind(WorksetKind.UserWorkset)
                               .ToWorksets()
                               .Where(w => w.Name == WorksetName)
                               .First();
                return(wset);
            }
            else
            {
                Workset wset = Workset.Create(doc, WorksetName);
                return(wset);
            }
        }
Exemple #27
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            // Access current selection
            ICollection <ElementId>    selected          = uidoc.Selection.GetElementIds();
            UserWorksetSelectionFilter userWorksetFilter = new UserWorksetSelectionFilter(doc);

            try
            {
                ElementId selectionId;

                selectionId = selected.FirstOrDefault(id => userWorksetFilter.IsUserWorksetElement(id));

                while (selectionId == null)
                {
                    Reference elRef = uidoc.Selection.PickObject(ObjectType.Element, userWorksetFilter, "Select an element");
                    selectionId = doc.GetElement(elRef).Id;
                }

                Element      element = doc.GetElement(selectionId);
                WorksetTable wsTable = doc.GetWorksetTable();
                Workset      workset = wsTable.GetWorkset(element.WorksetId);
                wsTable.SetActiveWorksetId(element.WorksetId);

                TaskDialog.Show("Workset By Element", $"Active workset changed to '{workset.Name}'");
                return(Result.Succeeded);
            }
            catch (Exception)
            {
                return(Result.Failed);
            }
        }
Exemple #28
0
        /// <summary>
        ///     Creates a workset.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="gridLvl"></param>
        /// <param name="worksetName"></param>
        /// <returns></returns>
        public static Workset AddWorkset(this Document doc, string gridLvl, string worksetName)
        {
            if (doc == null)
            {
                throw new ArgumentNullException(nameof(doc));
            }

            if (gridLvl == null)
            {
                throw new ArgumentNullException(nameof(gridLvl));
            }

            if (worksetName == null)
            {
                throw new ArgumentNullException(nameof(worksetName));
            }

            if (doc.IsWorkshared)
            {
                doc.EnableWorksharing(gridLvl, worksetName);
            }

            return(Workset.Create(doc, worksetName));
        }
Exemple #29
0
 /// <summary>
 /// 添加图元到指定工作集
 /// </summary>
 /// <param name="doc">当前项目</param>
 /// <param name="workset">要添加图元的工作集</param>
 /// <param name="element">要操作的图元</param>
 public void AddElementToWorkset(Document doc, Workset workset, List <Element> element)
 {
     if (workset != null)
     {
         int worksetId = workset.Id.IntegerValue;
         using (Transaction trans = new Transaction(doc, "将图元添加到指定工作集"))
         {
             trans.Start();
             foreach (Element ele in element)
             {
                 Parameter wspara = ele.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
                 if (wspara != null)
                 {
                     wspara.Set(worksetId);
                 }
             }
             trans.Commit();
         }
     }
     if (workset == null)
     {
         TaskDialog.Show("Revit", "工作集为空");
     }
 }
        private void MyWorksetExplorer(UIDocument UIdoc)
        {
            Document _doc = UIdoc.Document;

            // Выборка всех элементов в проекте
            IList <Element> allElements = new FilteredElementCollector(_doc).WhereElementIsNotElementType().ToElements();

            if (_doc.IsWorkshared)
            {
                WorksetTable           worksetTable = _doc.GetWorksetTable();
                IList <Workset>        worksets     = new FilteredWorksetCollector(_doc).OfKind(WorksetKind.UserWorkset).ToWorksets();
                List <List <Element> > allElsEls    = new List <List <Element> >(worksets.Count);
                foreach (Workset ws in worksets)
                {
                    allElsEls.Add(new List <Element>());
                }

                foreach (Element element in allElements)
                {
                    Workset workset = worksetTable.GetWorkset(element.WorksetId); // Get's the Workset Table of the document. Then return the workset from the input WorksetId
                    if (element.Category != null &&
                        (element.Category.Id.IntegerValue != (int)BuiltInCategory.OST_Grids &&
                         element.Category.Id.IntegerValue != (int)BuiltInCategory.OST_Levels &&
                         element.Category.Id.IntegerValue != (int)BuiltInCategory.OST_PreviewLegendComponents))
                    {
                        Parameter param = element.get_Parameter(BuiltInParameter.ELEM_PARTITION_PARAM);
                        if (param != null && !param.IsReadOnly)
                        {
                            bool flag  = false;
                            int  index = -1;
                            foreach (Workset ws in worksets)
                            {
                                ++index;
                                if (Equals(ws.Id, workset.Id))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                if (index != -1)
                                {
                                    allElsEls[index].Add(element);
                                }
                            }
                        }
                    }
                }


                var infoWorksetForm = new PRSPKT_Apps.ElementsOnWorkset.WorksetExplorerForm(allElsEls, _doc, ((IEnumerable <Workset>)worksets).ToArray());
                if (DialogResult.OK == infoWorksetForm.ShowDialog())
                {
                    List <Element> selectedElements = infoWorksetForm.GetSelectedElements();
                    UIdoc.Selection.SetElementIds(selectedElements.Select(q => q.Id).ToList());
                }
            }
            else
            {
                TaskDialog.Show("Ошибка", "Проект не переведён в режим совместной работы");
            }
        }