Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public static SpaceTag ToRevit_SpaceTag(this Tag tag, Document document, ConvertSettings convertSettings)
        {
            if (tag == null || document == null)
            {
                return(null);
            }

            Core.IntegerId integerId_Reference = tag.ReferenceId;
            if (integerId_Reference == null)
            {
                return(null);
            }

            if (tag.BuiltInCategory() != BuiltInCategory.OST_MEPSpaceTags)
            {
                return(null);
            }

            FamilySymbol familySymbol = tag.Type?.ToRevit(document, convertSettings);

            if (familySymbol == null)
            {
                return(null);
            }

            Core.IntegerId integerId_View = tag.ViewId;
            if (integerId_View == null)
            {
                return(null);
            }

            View view = Core.Revit.Query.Element <View>(document, integerId_View, true);

            if (view == null)
            {
                return(null);
            }

            Space space = Query.Find <Space>(document, integerId_Reference);

            if (space == null)
            {
                return(null);
            }

            UV location = tag.Location?.ToRevit();

            if (location == null)
            {
                return(null);
            }

            SpaceTag result = document.Create.NewSpaceTag(space, location, view);

            if (tag.TryGetValue(TagParameter.Leader, out bool leader) && leader)
            {
                result.HasLeader = leader;

                //XYZ xYZ = (result.Location as LocationPoint)?.Point;
                //if(xYZ != null)
                //{
                //    ElementTransformUtils.MoveElement(document, result.Id, new XYZ(location.U - xYZ.X, location.V - xYZ.Y, 0));
                //}

                UV elbow = tag.Elbow?.ToRevit();
                if (elbow != null)
                {
                    result.LeaderElbow = new XYZ(elbow.U, elbow.V, 0);
                }

                UV end = tag.End?.ToRevit();
                if (end != null)
                {
                    result.LeaderEnd = new XYZ(end.U, end.V, 0);
                }
            }

            if (tag.TryGetValue(TagParameter.Orientation, out string orientationText) && !string.IsNullOrWhiteSpace(orientationText))
            {
                if (System.Enum.TryParse(orientationText, out SpatialElementTagOrientation spatialElementTagOrientation) && result.TagOrientation != spatialElementTagOrientation)
                {
                    result.TagOrientation = spatialElementTagOrientation;
                }
            }

            result.ChangeTypeId(familySymbol.Id);

            return(result);
        }
Esempio n. 3
0
        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);
        }