Пример #1
0
        private void InitTag(
            Autodesk.Revit.DB.Element host,
            Autodesk.Revit.DB.TagOrientation orientation,
            Autodesk.Revit.DB.TagMode mode,
            bool addLeader,
            Autodesk.Revit.DB.XYZ point)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            var tagElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.IndependentTag>(document);

            if (tagElem == null)
            {
                tagElem = document.Create.NewTag(document.ActiveView, host, addLeader, mode, orientation, point);
            }

            InternalSetTag(tagElem);

            TransactionManager.Instance.TransactionTaskDone();


            if (tagElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Пример #2
0
        /// <summary>
        /// Create a Revit Tag for a Revit Element at an offset location
        /// from the element's view extents
        /// </summary>
        /// <param name="view">View to tag in</param>
        /// <param name="element">Element to tag</param>
        /// <param name="horizontal">Optional: Place tag horizontal,
        /// defaults to true</param>
        /// <param name="addLeader">Optional: Add a leader, defaults to false</param>
        /// <param name="offset">Optional: Offset Vector, defaults to 0,0,0</param>
        /// <param name="horizontalAlignment">Optional: Horizontal Alignment
        /// within the element's extents, defaults to Center</param>
        /// <param name="verticalAlignment">Optional: Vertical Alignment
        /// within the element's extents, defaults to Middle</param>
        /// <returns></returns>
        /// <search>
        /// tagelement,annotate,documentation,tagoffset,movetag
        /// </search>
        public static Tag ByElementAndOffset(Revit.Elements.Views.View view, Element element, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector offset, string horizontalAlignment = "Center", string verticalAlignment = "Middle", bool horizontal = true, bool addLeader = false)
        {
            Autodesk.Revit.DB.HorizontalAlignmentStyle horizontalAlignmentStyle = HorizontalAlignmentStyle.Center;
            if (!Enum.TryParse <Autodesk.Revit.DB.HorizontalAlignmentStyle>(horizontalAlignment, out horizontalAlignmentStyle))
            {
                horizontalAlignmentStyle = HorizontalAlignmentStyle.Center;
            }

            Autodesk.Revit.DB.VerticalAlignmentStyle verticalAlignmentStyle = VerticalAlignmentStyle.Middle;
            if (!Enum.TryParse <Autodesk.Revit.DB.VerticalAlignmentStyle>(verticalAlignment, out verticalAlignmentStyle))
            {
                verticalAlignmentStyle = VerticalAlignmentStyle.Middle;
            }

            Autodesk.Revit.DB.View revitView = (Autodesk.Revit.DB.View)view.InternalElement;

            // Tagging elements by element category
            Autodesk.Revit.DB.TagMode tagMode = TagMode.TM_ADDBY_CATEGORY;

            Autodesk.Revit.DB.TagOrientation orientation = (horizontal) ? TagOrientation.Horizontal : TagOrientation.Vertical;

            if (!view.IsAnnotationView())
            {
                throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations);
            }

            XYZ location = GetExtentsWithOffset(element, revitView, offset.ToRevitType(true), verticalAlignmentStyle, horizontalAlignmentStyle);

            return(new Tag(revitView, element.InternalElement, orientation, tagMode, addLeader, location));
        }
Пример #3
0
 private Tag(
     Autodesk.Revit.DB.Element host,
     Autodesk.Revit.DB.TagOrientation orientation,
     Autodesk.Revit.DB.TagMode mode,
     bool addLeader,
     Autodesk.Revit.DB.XYZ point)
 {
     SafeInit(() => InitTag(host, orientation, mode, addLeader, point));
 }
Пример #4
0
        /// <summary>
        /// Init Tag element
        /// </summary>
        /// <param name="view"></param>
        /// <param name="host"></param>
        /// <param name="orientation"></param>
        /// <param name="mode"></param>
        /// <param name="addLeader"></param>
        /// <param name="vector"></param>
        private void Init(
            Autodesk.Revit.DB.View view,
            Autodesk.Revit.DB.Element host,
            Autodesk.Revit.DB.TagOrientation orientation,
            Autodesk.Revit.DB.TagMode mode,
            bool addLeader,
            Autodesk.Revit.DB.XYZ vector)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.EnsureInTransaction(document);

            var tagElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.IndependentTag>(document);

            var hostElementIds   = new List <ElementId>();
            var linkedElementIds = new List <ElementId>();

            if (tagElem != null)
            {
                hostElementIds.AddRange(tagElem.GetTaggedElementIds().Select(x => x.HostElementId));
                linkedElementIds.AddRange(tagElem.GetTaggedElementIds().Select(x => x.LinkedElementId));
            }

            // create a new tag if the existing tag is null or its host view is not the selected one
            // or the host is neither set a host or linked element.
            if (tagElem == null || view.Id != tagElem.OwnerViewId ||
                (!hostElementIds.Contains(host.Id) && !linkedElementIds.Contains(host.Id)))
            {
                tagElem = IndependentTag.Create(Document, view.Id, new Autodesk.Revit.DB.Reference(host), addLeader, mode, orientation, vector);
            }
            else
            {
                // apply properties
                if (tagElem.TagOrientation != orientation)
                {
                    tagElem.TagOrientation = orientation;
                }

                if (tagElem.HasLeader != addLeader)
                {
                    tagElem.HasLeader = addLeader;
                }

                if (!tagElem.TagHeadPosition.Equals(vector))
                {
                    tagElem.TagHeadPosition = vector;
                }
            }

            double rotation = (orientation == TagOrientation.Horizontal) ? 0 : 90;

            InternalSetType(tagElem.TagText, tagElem.TagHeadPosition, rotation);
            InternalSetElement(tagElem);

            TransactionManager.Instance.TransactionTaskDone();
            ElementBinder.SetElementForTrace(this.InternalElement);
        }
Пример #5
0
 /// <summary>
 /// Tag by Element
 /// </summary>
 /// <param name="view"></param>
 /// <param name="host"></param>
 /// <param name="orientation"></param>
 /// <param name="mode"></param>
 /// <param name="addLeader"></param>
 /// <param name="point"></param>
 private Tag(
     Autodesk.Revit.DB.View view,
     Autodesk.Revit.DB.Element host,
     Autodesk.Revit.DB.TagOrientation orientation,
     Autodesk.Revit.DB.TagMode mode,
     bool addLeader,
     Autodesk.Revit.DB.XYZ vector)
 {
     SafeInit(() => Init(view, host, orientation, mode, addLeader, vector));
 }
Пример #6
0
        /// <summary>
        /// Create a Revit Tag for a Revit Element at a specified location point
        /// </summary>
        /// <param name="view">View to tag in</param>
        /// <param name="element">Element to tag</param>
        /// <param name="location">Location point</param>
        /// <param name="horizontal">Optional: Place tag horizontal, defaults to true</param>
        /// <param name="addLeader">Optional: Add a leader, defaults to false</param>
        /// <returns></returns>
        /// <search>
        /// tagelement,annotate,documentation,taglocation
        /// </search>
        public static Tag ByElementAndLocation(Revit.Elements.Views.View view, Element element, Autodesk.DesignScript.Geometry.Point location, bool horizontal = true, bool addLeader = false)
        {
            Autodesk.Revit.DB.View           revitView   = (Autodesk.Revit.DB.View)view.InternalElement;
            Autodesk.Revit.DB.XYZ            point       = location.ToRevitType(true);
            Autodesk.Revit.DB.TagMode        tagMode     = TagMode.TM_ADDBY_CATEGORY;
            Autodesk.Revit.DB.TagOrientation orientation = (horizontal) ? TagOrientation.Horizontal : TagOrientation.Vertical;

            if (!view.IsAnnotationView())
            {
                throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations);
            }

            return(new Tag(revitView, element.InternalElement, orientation, tagMode, addLeader, point));
        }
Пример #7
0
        /// <summary>
        /// Create an element based Tag
        /// </summary>
        /// <param name="element">Element to tag</param>
        /// <param name="horizontal">Horizontal alignment</param>
        /// <param name="addLeader">Add a leader</param>
        /// <returns></returns>
        public static Tag ByElement(Element element, bool horizontal, bool addLeader)
        {
            Autodesk.Revit.DB.Document       document    = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.XYZ            point       = null;
            Autodesk.Revit.DB.TagMode        tagMode     = TagMode.TM_ADDBY_CATEGORY;
            Autodesk.Revit.DB.TagOrientation orientation = (horizontal)? TagOrientation.Horizontal : TagOrientation.Vertical;

            if (document.ActiveView.ViewType != ViewType.FloorPlan &&
                document.ActiveView.ViewType != ViewType.EngineeringPlan &&
                document.ActiveView.ViewType != ViewType.Detail &&
                document.ActiveView.ViewType != ViewType.Section &&
                document.ActiveView.ViewType != ViewType.Elevation &&
                document.ActiveView.ViewType != ViewType.CeilingPlan)
            {
                throw new ArgumentException("Cannot place a Tag on active View");
            }


            if (element.InternalElement.Location.GetType() == typeof(LocationPoint))
            {
                LocationPoint locationPoint = (LocationPoint)element.InternalElement.Location;
                point = locationPoint.Point;
            }
            else if (element.InternalElement.Location.GetType() == typeof(LocationCurve))
            {
                LocationCurve locationCurve = (LocationCurve)element.InternalElement.Location;
                point = locationCurve.Curve.GetEndPoint(0);
            }
            else
            {
                BoundingBoxXYZ box = element.InternalElement.get_BoundingBox(document.ActiveView);
                if (box == null)
                {
                    box = element.InternalElement.get_BoundingBox(null);
                }
                if (box != null)
                {
                    point = box.Min + ((box.Max - box.Min) / 2);
                }
                else
                {
                    throw new ArgumentNullException("Cannot determine location");
                }
            }


            return(new Tag(element.InternalElement, orientation, tagMode, addLeader, point));
        }
Пример #8
0
        private void InitTag(
            Autodesk.Revit.DB.View view,
            Autodesk.Revit.DB.Element host,
            Autodesk.Revit.DB.TagOrientation orientation,
            Autodesk.Revit.DB.TagMode mode,
            bool addLeader,
            Autodesk.Revit.DB.XYZ point)
        {
            Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            var tagElem = ElementBinder.GetElementFromTrace <Autodesk.Revit.DB.IndependentTag>(document);


            if (tagElem == null ||
                view.Id != tagElem.OwnerViewId ||
                (tagElem.TaggedElementId.HostElementId != host.Id && tagElem.TaggedElementId.LinkedElementId != host.Id))
            {
                tagElem = document.Create.NewTag(view, host, addLeader, mode, orientation, point);
            }
            else
            {
                tagElem.TagOrientation  = orientation;
                tagElem.HasLeader       = addLeader;
                tagElem.TagHeadPosition = point;
            }

            InternalSetTag(tagElem);

            TransactionManager.Instance.TransactionTaskDone();


            if (tagElem != null)
            {
                ElementBinder.CleanupAndSetElementForTrace(document, this.InternalElement);
            }
            else
            {
                ElementBinder.SetElementForTrace(this.InternalElement);
            }
        }
Пример #9
0
        /// <summary>
        /// Create a Revit Tag for a Revit Element
        /// </summary>
        /// <param name="view">View to Tag</param>
        /// <param name="element">Element to tag</param>
        /// <param name="horizontal">Horizontal alignment</param>
        /// <param name="addLeader">Add a leader</param>
        /// <param name="offset">Offset Vector or Tag Location</param>
        /// <param name="isOffset">Specifies if the point is being used as an offset vector or if it specifies the tags location</param>
        /// <param name="horizontalAlignment">Horizontal Alignment</param>
        /// <param name="verticalAlignment">Vertical Alignment</param>
        /// <returns></returns>
        public static Tag ByElement(Revit.Elements.Views.View view, Element element, bool horizontal, bool addLeader, string horizontalAlignment, string verticalAlignment, [DefaultArgument("Autodesk.DesignScript.Geometry.Vector.ByCoordinates(0,0,0)")] Autodesk.DesignScript.Geometry.Vector offset, bool isOffset = true)
        {
            Autodesk.Revit.DB.HorizontalAlignmentStyle horizontalAlignmentStyle = HorizontalAlignmentStyle.Center;
            if (!Enum.TryParse <Autodesk.Revit.DB.HorizontalAlignmentStyle>(horizontalAlignment, out horizontalAlignmentStyle))
            {
                horizontalAlignmentStyle = HorizontalAlignmentStyle.Center;
            }

            Autodesk.Revit.DB.VerticalAlignmentStyle verticalAlignmentStyle = VerticalAlignmentStyle.Middle;
            if (!Enum.TryParse <Autodesk.Revit.DB.VerticalAlignmentStyle>(verticalAlignment, out verticalAlignmentStyle))
            {
                verticalAlignmentStyle = VerticalAlignmentStyle.Middle;
            }



            Autodesk.Revit.DB.View           revitView   = (Autodesk.Revit.DB.View)view.InternalElement;
            Autodesk.Revit.DB.XYZ            point       = offset.ToRevitType(true);
            Autodesk.Revit.DB.TagMode        tagMode     = TagMode.TM_ADDBY_CATEGORY;
            Autodesk.Revit.DB.TagOrientation orientation = (horizontal) ? TagOrientation.Horizontal : TagOrientation.Vertical;

            if (!view.IsAnnotationView())
            {
                throw new Exception(Properties.Resources.ViewDoesNotSupportAnnotations);
            }

            if (isOffset)
            {
                BoundingBoxXYZ box = element.InternalElement.get_BoundingBox(revitView);
                if (box == null)
                {
                    box = element.InternalElement.get_BoundingBox(null);
                }
                if (box != null)
                {
                    double Y, X = 0;

                    switch (verticalAlignmentStyle)
                    {
                    case VerticalAlignmentStyle.Bottom: Y = box.Min.Y; break;

                    case VerticalAlignmentStyle.Top: Y = box.Max.Y; break;

                    default: Y = box.Min.Y + ((box.Max.Y - box.Min.Y) / 2); break;
                    }

                    switch (horizontalAlignmentStyle)
                    {
                    case HorizontalAlignmentStyle.Left: X = box.Min.X; break;

                    case HorizontalAlignmentStyle.Right: X = box.Max.X; break;

                    default: X = box.Min.X + ((box.Max.X - box.Min.X) / 2); break;
                    }

                    point = new XYZ(X + point.X, Y + point.Y, 0 + point.Z);
                }
                else
                {
                    if (element.InternalElement.Location != null)
                    {
                        if (element.InternalElement.Location.GetType() == typeof(LocationCurve))
                        {
                            LocationCurve lc       = (LocationCurve)element.InternalElement.Location;
                            XYZ           midpoint = lc.Curve.Evaluate(0.5, true);
                            point = new XYZ(midpoint.X + point.X, midpoint.Y + point.Y, 0 + point.Z);
                        }
                        else if (element.InternalElement.Location.GetType() == typeof(LocationPoint))
                        {
                            LocationPoint lp = (LocationPoint)element.InternalElement.Location;
                            point = new XYZ(lp.Point.X + point.X, lp.Point.Y + point.Y, 0 + point.Z);
                        }
                        else
                        {
                            throw new Exception(Properties.Resources.InvalidElementLocation);
                        }
                    }
                    else
                    {
                        throw new Exception(Properties.Resources.InvalidElementLocation);
                    }
                }
            }



            return(new Tag(revitView, element.InternalElement, orientation, tagMode, addLeader, point));
        }
Пример #10
0
        /// <summary>
        /// Create an element based Tag
        /// </summary>
        /// <param name="view">View to Tag</param>
        /// <param name="element">Element to tag</param>
        /// <param name="horizontal">Horizontal alignment</param>
        /// <param name="addLeader">Add a leader</param>
        /// <param name="offset">Offset Vector or Tag Location</param>
        /// <param name="isOffset">Specifies if the point is being used as an offset vector or if it specifies the tags location</param>
        /// <param name="horizontalAlignment">Horizontal Alignment</param>
        /// <param name="verticalAlignment">Vertical Alignment</param>
        /// <returns></returns>
        public static Tag ByElement(Revit.Elements.Views.View view, Element element, bool horizontal, bool addLeader, Autodesk.DesignScript.Geometry.Point offset = null, bool isOffset = true, string horizontalAlignment = "Center", string verticalAlignment = "Middle")
        {
            if (offset == null)
            {
                offset = Autodesk.DesignScript.Geometry.Point.ByCoordinates(0, 0, 0);
            }

            Autodesk.Revit.DB.HorizontalAlignmentStyle alignHorizontal = Autodesk.Revit.DB.HorizontalAlignmentStyle.Center;
            Enum.TryParse <Autodesk.Revit.DB.HorizontalAlignmentStyle>(horizontalAlignment, out alignHorizontal);

            Autodesk.Revit.DB.VerticalAlignmentStyle alignVertical = Autodesk.Revit.DB.VerticalAlignmentStyle.Middle;
            Enum.TryParse <Autodesk.Revit.DB.VerticalAlignmentStyle>(verticalAlignment, out alignVertical);

            //Autodesk.Revit.DB.Document document = DocumentManager.Instance.CurrentDBDocument;
            Autodesk.Revit.DB.View           revitView   = (Autodesk.Revit.DB.View)view.InternalElement;
            Autodesk.Revit.DB.XYZ            point       = offset.ToRevitType(true);
            Autodesk.Revit.DB.TagMode        tagMode     = TagMode.TM_ADDBY_CATEGORY;
            Autodesk.Revit.DB.TagOrientation orientation = (horizontal) ? TagOrientation.Horizontal : TagOrientation.Vertical;

            if (revitView.ViewType != ViewType.FloorPlan &&
                revitView.ViewType != ViewType.EngineeringPlan &&
                revitView.ViewType != ViewType.Detail &&
                revitView.ViewType != ViewType.Section &&
                revitView.ViewType != ViewType.Elevation &&
                revitView.ViewType != ViewType.CeilingPlan)
            {
                throw new ArgumentException("Cannot place a Tag on active View");
            }

            if (isOffset)
            {
                BoundingBoxXYZ box = element.InternalElement.get_BoundingBox(revitView);
                if (box == null)
                {
                    box = element.InternalElement.get_BoundingBox(null);
                }
                if (box != null)
                {
                    double Y, X = 0;

                    switch (alignVertical)
                    {
                    case VerticalAlignmentStyle.Bottom: Y = box.Min.Y; break;

                    case VerticalAlignmentStyle.Top: Y = box.Max.Y; break;

                    default: Y = box.Min.Y + ((box.Max.Y - box.Min.Y) / 2); break;
                    }

                    switch (alignHorizontal)
                    {
                    case HorizontalAlignmentStyle.Left: X = box.Min.X; break;

                    case HorizontalAlignmentStyle.Right: X = box.Max.X; break;

                    default: X = box.Min.X + ((box.Max.X - box.Min.X) / 2); break;
                    }

                    point = new XYZ(X + point.X, Y + point.Y, 0 + point.Z);
                }
                else
                {
                    if (element.InternalElement.Location != null)
                    {
                        if (element.InternalElement.Location.GetType() == typeof(LocationCurve))
                        {
                            LocationCurve lc       = (LocationCurve)element.InternalElement.Location;
                            XYZ           midpoint = lc.Curve.Evaluate(0.5, true);
                            point = new XYZ(midpoint.X + point.X, midpoint.Y + point.Y, 0 + point.Z);
                        }
                        else if (element.InternalElement.Location.GetType() == typeof(LocationPoint))
                        {
                            LocationPoint lp = (LocationPoint)element.InternalElement.Location;
                            point = new XYZ(lp.Point.X + point.X, lp.Point.Y + point.Y, 0 + point.Z);
                        }
                        else
                        {
                            throw new ArgumentNullException("Cannot determine location");
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException("Cannot determine location");
                    }
                }
            }



            return(new Tag(revitView, element.InternalElement, orientation, tagMode, addLeader, point));
        }