示例#1
0
        public void BeWorkset(string _wsName, ExternalCommandData commandData)
        {
            UIApplication _uiapp = commandData.Application;
            UIDocument    _uidoc = _uiapp.ActiveUIDocument;

            Autodesk.Revit.ApplicationServices.Application _app = _uiapp.Application;
            Autodesk.Revit.DB.Document _doc = _uidoc.Document;
            WorksetTable wst  = _doc.GetWorksetTable();
            WorksetId    wsID = FamilyUtils.WhatIsThisWorkSetIDByName(_wsName, _doc);

            if (wsID != null)
            {
                using (Transaction trans = new Transaction(_doc, "WillChangeWorkset")) {
                    trans.Start();
                    wst.SetActiveWorksetId(wsID);
                    trans.Commit();
                }
            }
            else
            {
                System.Windows.MessageBox.Show("Sorry but there is no workset "
                                               + _wsName + " to switch to.", "Smells So Bad It Has A Chain On It",
                                               System.Windows.MessageBoxButton.OK,
                                               System.Windows.MessageBoxImage.Exclamation);
            }
        }
示例#2
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);
            }
        }