public static Workset GetActiveWorkset(Document doc) { WorksetTable table = doc.GetWorksetTable(); WorksetId activeId = table.GetActiveWorksetId(); Workset workset = table.GetWorkset(activeId); return(workset); }
public ElementProps(Element el) { Document doc = el.Document; ID = el.Id.IntegerValue; Name = el.Name; ClassName = el.GetType().ToString().Replace("Autodesk.Revit.DB.", string.Empty); CategoryName = (null != el.Category) ? el.Category.Name : ElementPropertiesWrapper.NullDescrip; LevelName = (ElementId.InvalidElementId == el.LevelId) ? ElementPropertiesWrapper.NullDescrip : doc.GetElement(el.LevelId).Name; IsWorkshared = doc.IsWorkshared; if (IsWorkshared) { WorksetTable wsTbl = doc.GetWorksetTable(); WorksetName = (WorksetId.InvalidWorksetId != el.WorksetId) ? wsTbl.GetWorkset(el.WorksetId).Name : ElementPropertiesWrapper.NullDescrip; } else { WorksetName = ElementPropertiesWrapper.NullDescrip; } IsViewSpecific = el.ViewSpecific; if (IsViewSpecific) { OwnerViewId = el.OwnerViewId.IntegerValue; } else { OwnerViewId = null; } OwnerViewName = IsViewSpecific ? doc.GetElement(el.OwnerViewId).Name : string.Empty; if (null == el.DesignOption) { DesignOptionSet = DesignOptionName = string.Empty; } else { // Might need to parse this?.. DesignOptionSet = el.DesignOption.Name; DesignOptionName = el.DesignOption.Name; } PhaseName = (el.CreatedPhaseId == ElementId.InvalidElementId) ? ElementPropertiesWrapper.NullDescrip : doc.GetElement(el.CreatedPhaseId).Name; }
public ElementProps(Element el) { Document doc = el.Document; RevitFilePath = doc.PathName; IsBim360Model = doc.IsModelInCloud; ProjectNumber = doc.ProjectInformation.Number; ProjectName = doc.ProjectInformation.Name; FileVersion = doc.Application.VersionNumber; ID = el.Id.IntegerValue; Name = el.Name; ClassName = el.GetType().ToString().Replace("Autodesk.Revit.DB.", string.Empty); CategoryName = (null != el.Category) ? el.Category.Name : ElementPropertiesWrapper.NullDescrip; LevelName = (ElementId.InvalidElementId == el.LevelId) ? ElementPropertiesWrapper.NullDescrip : doc.GetElement(el.LevelId).Name; IsWorkshared = doc.IsWorkshared; if (IsWorkshared) { WorksetTable wsTbl = doc.GetWorksetTable(); WorksetName = (WorksetId.InvalidWorksetId != el.WorksetId) ? wsTbl.GetWorkset(el.WorksetId).Name : ElementPropertiesWrapper.NullDescrip; } else { WorksetName = ElementPropertiesWrapper.NullDescrip; } IsViewSpecific = el.ViewSpecific; OwnerViewName = IsViewSpecific ? doc.GetElement(el.OwnerViewId).Name : string.Empty; if (null == el.DesignOption) DesignOptionSet = DesignOptionName = string.Empty; else { // Might need to parse this?.. DesignOptionSet = el.DesignOption.Name; DesignOptionName = el.DesignOption.Name; } PhaseName = (el.CreatedPhaseId == ElementId.InvalidElementId) ? ElementPropertiesWrapper.NullDescrip : doc.GetElement(el.CreatedPhaseId).Name; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; WorksetTable worksetTable = doc.GetWorksetTable(); // Build hashmap out of all selected elements and store their filterable properties Selection selection = uidoc.Selection; allElements = selection.GetElementIds().Select(id => { Element element = doc.GetElement(id); FilterableElement filterableElement; filterableElement.id = id; filterableElement.category = element.Category.Name; filterableElement.family = element.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString(); filterableElement.type = element.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM).AsValueString(); filterableElement.workset = worksetTable.GetWorkset(element.WorksetId).Name; return(filterableElement); }).ToList(); filteredElements = allElements; // Determine the values we can filter determineAvailableFilters(); allFilters = availableFilters; selectedFilters = availableFilters; // Show the form FilterForm filterForm = new FilterForm(this, availableFilters); DialogResult result = filterForm.ShowDialog(); if (DialogResult.Cancel == result) { filteredElements = allElements; } // Select the filtered elements in Revit selection.SetElementIds(filteredElements.Select(filterableElement => filterableElement.id).ToList()); return(Result.Succeeded); }
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); } }
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("Ошибка", "Проект не переведён в режим совместной работы"); } }
private static bool SetValue_Integer(this Parameter parameter, object value) { if (parameter == null || value == null) { return(false); } if (value is int) { //Check if parameter is Workset parameter -> If Workset parameter then change only if Workset with Id exists if (parameter.Id.IntegerValue == (int)BuiltInParameter.ELEM_PARTITION_PARAM) { WorksetTable worksetTable = parameter.Element?.Document?.GetWorksetTable(); if (worksetTable == null) { return(false); } WorksetId worksetId = new WorksetId((int)value); if (WorksetId.InvalidWorksetId == worksetId) { return(false); } //TODO: Double check if workset is valid! Workset workset = worksetTable.GetWorkset(worksetId); if (workset == null || workset.Kind != WorksetKind.UserWorkset) { return(false); } } parameter.Set((int)value); return(true); } else if (value is string) { string value_Temp = (string)value; int @int; if (int.TryParse(value_Temp, out @int)) { parameter.Set(@int); return(true); } //YesNo Type parameter if (parameter.Definition.ParameterType == Autodesk.Revit.DB.ParameterType.YesNo) { value_Temp = value_Temp.ToUpper().Trim(); if (value_Temp.Equals("Y") || value_Temp.Equals("YES") || value_Temp.Equals("+") || value_Temp.Equals("TRUE")) { parameter.Set(1); return(true); } if (value_Temp.Equals("N") || value_Temp.Equals("NO") || value_Temp.Equals("-") || value_Temp.Equals("FALSE")) { parameter.Set(0); return(true); } return(false); } } else if (value is bool) { if ((bool)value) { parameter.Set(1); } else { parameter.Set(0); } return(true); } else if (value is IntegerId) { parameter.Set(((IntegerId)value).Id); return(true); } return(false); }
/// <summary> /// Find the WorksetKind for an element /// </summary> /// <param name="elem">the Element to check</param> /// <returns>The WorksetKind of the Element</returns> WorksetKind GetWorksetKind(Element elem) { WorksetTable wksetTbl = elem.Document.GetWorksetTable(); return(wksetTbl.GetWorkset(elem.WorksetId).Kind); }