public static Dictionary <string, object> CopyElements(List <Revit.Elements.Element> element,
                                                               Autodesk.DesignScript.Geometry.Point translation)
        {
            //declare an elementId collection and add the ids to it.
            List <Autodesk.Revit.DB.ElementId> idCollection = new List <Autodesk.Revit.DB.ElementId>();

            foreach (var item in element)
            {
                var internalElement = (Autodesk.Revit.DB.Element)item.InternalElement;
                idCollection.Add(internalElement.Id);
            }
            //start the transaction to copy elements
            Document doc        = DocumentManager.Instance.CurrentDBDocument;
            var      revitPoint = translation.ToRevitType();

            TransactionManager.Instance.EnsureInTransaction(doc);
            var newElementIds = ElementTransformUtils.CopyElements(doc, idCollection, revitPoint);

            TransactionManager.Instance.TransactionTaskDone();
            //declare new list to append the new elements to it
            List <Revit.Elements.Element> newElements = new List <Revit.Elements.Element>();

            foreach (var item in newElementIds)
            {
                newElements.Add(doc.GetElement(item).ToDSType(true));
            }

            //returns the outputs
            var outInfo = new Dictionary <string, object>
            {
                { "element", newElements }
            };

            return(outInfo);
        }
Example #2
0
        /// <summary>
        /// Set the position of the leader end for a tag using free end leader behavior.
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public Tag SetLeaderEnd(Autodesk.DesignScript.Geometry.Point location)
        {
            Autodesk.Revit.DB.XYZ            point    = location.ToRevitType(true);
            Autodesk.Revit.DB.IndependentTag tagElem  = this.InternalTextNote;
            Autodesk.Revit.DB.Document       document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            tagElem.LeaderEnd = point;

            TransactionManager.Instance.TransactionTaskDone();
            return(this);
        }
Example #3
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));
        }
Example #4
0
        /// <summary>
        /// Set the position of the head of tag.
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public Tag SetHeadLocation(Autodesk.DesignScript.Geometry.Point location)
        {
            Autodesk.Revit.DB.XYZ            point    = location.ToRevitType(true);
            Autodesk.Revit.DB.IndependentTag tagElem  = this.InternalTextNote;
            Autodesk.Revit.DB.Document       document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            tagElem.TagHeadPosition = point;

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

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

            TransactionManager.Instance.TransactionTaskDone();
            return(this);
        }
Example #5
0
        /// <summary>
        /// Construct a new Revit TextNote by Location
        /// </summary>
        /// <param name="view">View to place text element on</param>
        /// <param name="location">Location in view</param>
        /// <param name="text">Text</param>
        /// <param name="alignment">Text alignment</param>
        /// <param name="keepRotatedTextReadable">Keep text horizontal</param>
        /// <param name="rotation">Rotation in degrees</param>
        /// <param name="type">Revit TextNote Type</param>
        /// <returns></returns>
        public static TextNote ByLocation(Revit.Elements.Views.View view, Autodesk.DesignScript.Geometry.Point location, string text, string alignment, [DefaultArgument("Revit.Elements.TextNoteType.Default()")] TextNoteType type, bool keepRotatedTextReadable = true, double rotation = 0)
        {
            RVT.HorizontalTextAlignment horizontalTextAlignmentStyle = HorizontalTextAlignment.Center;
            if (!Enum.TryParse <RVT.HorizontalTextAlignment>(alignment, out horizontalTextAlignmentStyle))
            {
                horizontalTextAlignmentStyle = HorizontalTextAlignment.Center;
            }

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

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

            return(new TextNote(revitView, location.ToRevitType(true), horizontalTextAlignmentStyle, text, keepRotatedTextReadable, rotation, type.InternalElement.Id));
        }
Example #6
0
        public static List <global::Revit.Elements.Element> AddGridLineByPoint(Autodesk.Revit.DB.CurtainGrid curtainGrid, Autodesk.DesignScript.Geometry.Point locationPoint, bool isUGridline)
        {
            List <Autodesk.Revit.DB.XYZ> revitPoint = new List <Autodesk.Revit.DB.XYZ>();

            revitPoint.Add(locationPoint.ToRevitType());
            List <global::Revit.Elements.Element> newElements = new List <global::Revit.Elements.Element>();

            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            TransactionManager.Instance.EnsureInTransaction(doc);
            foreach (var point in revitPoint)
            {
                newElements.Add(curtainGrid.AddGridLine(isUGridline, point, false).ToDSType(true));
            }
            ;
            TransactionManager.Instance.TransactionTaskDone();

            return(newElements);
        }
Example #7
0
        /// <summary>
        /// Set the position of the leader end for a tag using free end leader behavior.
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public Tag SetLeaderEnd(Autodesk.DesignScript.Geometry.Point location)
        {
            Autodesk.Revit.DB.XYZ            point    = location.ToRevitType(true);
            Autodesk.Revit.DB.IndependentTag tagElem  = this.InternalTextNote;
            Autodesk.Revit.DB.Document       document = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(document);

            var refs = InternalTextNote.GetTaggedReferences();

            if (refs.Count == 1)
            {
                tagElem.SetLeaderEnd(refs.First(), point);
            }
            else
            {
                throw new Exception(Properties.Resources.GetTaggedReferences);
            }

            TransactionManager.Instance.TransactionTaskDone();
            return(this);
        }
Example #8
0
 /// <summary>
 /// Check if a point is inside of a room
 /// </summary>
 public bool IsInsideRoom(Autodesk.DesignScript.Geometry.Point point)
 {
     return(this.InternalRevitElement.IsPointInRoom(point.ToRevitType()));
 }
Example #9
0
 /// <summary>
 /// Create a Revit Room Element
 /// </summary>
 /// <param name="level">Level the room is hosted on</param>
 /// <param name="location">Location for the center of the room</param>
 /// <param name="name">Room name</param>
 /// <param name="number">Room number</param>
 /// <returns></returns>
 public static Room ByLocation(Elements.Level level, Autodesk.DesignScript.Geometry.Point location, string name = "", string number = "")
 {
     return(new Room((Autodesk.Revit.DB.Level)level.InternalElement, location.ToRevitType(true), name, number));
 }
        /// <summary>
        /// Creates a reference section.
        /// </summary>
        /// <param name="parentView"></param>
        /// <param name="viewToReference"></param>
        /// <param name="headPoint"></param>
        /// <param name="tailPoint"></param>
        public static void CreateReferenceSection(global::Revit.Elements.Element parentView,
                                                  global::Revit.Elements.Element viewToReference, Point headPoint, Point tailPoint)
        {
            //the current document
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;

            TransactionManager.Instance.EnsureInTransaction(doc);
            Autodesk.Revit.DB.ViewSection.CreateReferenceSection(doc, parentView.InternalElement.Id, viewToReference.InternalElement.Id, headPoint.ToRevitType(), tailPoint.ToRevitType());
            TransactionManager.Instance.TransactionTaskDone();
        }
Example #11
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));
        }