public static Tag ToSAM(this SpaceTag spaceTag, ConvertSettings convertSettings) { if (spaceTag == null) { return(null); } Document document = spaceTag.Document; if (document == null) { return(null); } Tag result = convertSettings?.GetObject <Tag>(spaceTag.Id); if (result != null) { return(result); } TagType tagType = ToSAM(document.GetElement(spaceTag.GetTypeId()) as SpaceTagType, convertSettings); if (tagType == null) { return(null); } ElementId elementId = spaceTag.OwnerViewId; if (elementId == null) { return(null); } View view = document.GetElement(elementId) as View; if (view == null) { return(null); } IntegerId viewId = Query.IntegerId(view); IntegerId referenceId = Query.IntegerId(spaceTag.Space); Spatial.Point3D location = ToSAM(spaceTag.TagHeadPosition); if (location == null) { return(null); } Planar.Point2D elbow = null; Planar.Point2D end = null; if (spaceTag.HasLeader) { #if Revit2017 #else if (spaceTag.HasElbow) { Spatial.Point3D elbow3D = ToSAM(spaceTag.LeaderElbow); if (elbow3D != null) { elbow = new Planar.Point2D(elbow3D.X, elbow3D.Y); } } #endif Spatial.Point3D end3D = ToSAM(spaceTag.LeaderEnd); if (end3D != null) { end = new Planar.Point2D(end3D.X, end3D.Y); } } result = new Tag(tagType, viewId, new Planar.Point2D(location.X, location.Y), elbow, end, referenceId); if (result != null) { result.SetValue(ElementParameter.RevitId, Query.IntegerId(spaceTag)); result.SetValue(TagParameter.Leader, spaceTag.HasLeader); result.SetValue(TagParameter.Orientation, spaceTag.TagOrientation.ToString()); Core.Revit.Modify.SetValues(spaceTag, result); convertSettings?.Add(spaceTag.Id, result); } return(result); }
public static List <SpaceTag> TagSpaces(this View view, ElementId elementId_SpaceTagType, bool allowDuplicates = false) { if (view == null || elementId_SpaceTagType == null || elementId_SpaceTagType == ElementId.InvalidElementId) { return(null); } Document document = view.Document; SpaceTagType spaceTagType = document.GetElement(elementId_SpaceTagType) as SpaceTagType; if (spaceTagType == null) { return(null); } IEnumerable <Space> spaces = new FilteredElementCollector(document, view.Id).OfCategory(BuiltInCategory.OST_MEPSpaces).Cast <Space>(); if (spaces == null) { return(null); } List <SpaceTag> result = new List <SpaceTag>(); if (spaces.Count() == 0) { return(result); } foreach (Space space in spaces) { if (space == null || !space.IsValidObject) { continue; } if (!allowDuplicates) { #if Revit2017 IList <ElementId> elementIds = null; #else IList <ElementId> elementIds = space.GetDependentElements(new LogicalAndFilter(new ElementCategoryFilter(BuiltInCategory.OST_MEPSpaceTags), new ElementOwnerViewFilter(view.Id))); #endif if (elementIds != null) { ElementId elementId_Temp = elementIds.ToList().Find(x => document.GetElement(x)?.GetTypeId() == elementId_SpaceTagType); if (elementId_Temp != null) { continue; } } } Autodesk.Revit.DB.Location location = space.Location; if (location == null) { continue; } XYZ xyz = null; if (location is LocationPoint) { xyz = ((LocationPoint)location).Point; } if (xyz == null) { continue; } SpaceTag spaceTag = document.Create.NewSpaceTag(space, new UV(xyz.X, xyz.Y), view); if (spaceTag == null) { continue; } if (spaceTag.GetTypeId() != elementId_SpaceTagType) { spaceTag.SpaceTagType = spaceTagType; } result.Add(spaceTag); } return(result); }