public XYZ GetLeaderEnd()
        {
            XYZ     xyz    = this.Center;
            Element parent = this.Parent;

            if (((object)parent).GetType() == typeof(IndependentTag))
            {
                IndependentTag tag = parent as IndependentTag;
                if (tag.get_HasLeader())
                {
                    xyz = tag.get_LeaderEndCondition() != 1 ? TagLeader.GetLeaderEnd(TagLeader.GetTaggedElement(this._doc, tag), this._ownerView) : tag.get_LeaderEnd();
                }
            }
            else if (((object)parent).GetType() == typeof(TextNote))
            {
                TextNote textNote = parent as TextNote;
                if ((uint)textNote.get_LeaderCount() > 0U)
                {
                    xyz = ((IEnumerable <Leader>)textNote.GetLeaders()).FirstOrDefault <Leader>().get_End();
                }
            }
            else if (((object)parent).GetType().IsSubclassOf(typeof(SpatialElementTag)))
            {
                SpatialElementTag spatialElementTag = parent as SpatialElementTag;
                if (spatialElementTag.get_HasLeader())
                {
                    xyz = spatialElementTag.get_LeaderEnd();
                }
            }
            else
            {
                xyz = this.Center;
            }
            return(xyz);
        }
예제 #2
0
        private void ArrangeTag(UIDocument uidoc, Transaction tx)
        {
            Document document   = uidoc.get_Document();
            View     activeView = document.get_ActiveView();

            if (!activeView.get_CropBoxActive())
            {
                throw new ErrorMessageException("Please set a crop box to the view");
            }
            IEnumerable <IndependentTag> independentTags = ((IEnumerable <Element>) new FilteredElementCollector(document, ((Element)activeView).get_Id()).OfClass(typeof(IndependentTag)).WhereElementIsNotElementType()).Select(elem => new
            {
                elem = elem,
                type = elem as IndependentTag
            }).Where(_param1 => _param1.type.get_HasLeader()).Select(_param1 => _param1.type);

            tx.Start("Prepare Tags");
            using (IEnumerator <IndependentTag> enumerator = independentTags.GetEnumerator())
            {
                while (((IEnumerator)enumerator).MoveNext())
                {
                    IndependentTag current = enumerator.Current;
                    current.set_LeaderEndCondition((LeaderEndCondition)1);
                    current.set_LeaderEnd(current.get_TagHeadPosition());
                }
            }
            tx.Commit();
            tx.Start("Arrange Tags");
            List <TagLeader> tagLeaderList1 = new List <TagLeader>();
            List <TagLeader> tagLeaderList2 = new List <TagLeader>();

            using (IEnumerator <IndependentTag> enumerator = independentTags.GetEnumerator())
            {
                while (((IEnumerator)enumerator).MoveNext())
                {
                    TagLeader tagLeader = new TagLeader(enumerator.Current, document);
                    if (tagLeader.Side == ViewSides.Left)
                    {
                        tagLeaderList1.Add(tagLeader);
                    }
                    else
                    {
                        tagLeaderList2.Add(tagLeader);
                    }
                }
            }
            List <XYZ>       tagPositionPoints1 = this.CreateTagPositionPoints(activeView, tagLeaderList1, ViewSides.Left);
            List <XYZ>       tagPositionPoints2 = this.CreateTagPositionPoints(activeView, tagLeaderList2, ViewSides.Right);
            List <TagLeader> list1 = tagLeaderList1.OrderBy <TagLeader, double>((Func <TagLeader, double>)(x => x.LeaderEnd.get_X())).ToList <TagLeader>().OrderBy <TagLeader, double>((Func <TagLeader, double>)(x => x.LeaderEnd.get_Y())).ToList <TagLeader>();

            this.PlaceAndSort(tagPositionPoints1, list1);
            List <TagLeader> list2 = tagLeaderList2.OrderByDescending <TagLeader, double>((Func <TagLeader, double>)(x => x.LeaderEnd.get_X())).ToList <TagLeader>().OrderBy <TagLeader, double>((Func <TagLeader, double>)(x => x.LeaderEnd.get_Y())).ToList <TagLeader>();

            this.PlaceAndSort(tagPositionPoints2, list2);
            tx.Commit();
        }
예제 #3
0
 public TagLeader(IndependentTag tag, Document doc)
 {
     this._doc             = doc;
     this._currentView     = this._doc.GetElement(((Element)tag).get_OwnerViewId()) as View;
     this._tag             = tag;
     this._taggedElement   = TagLeader.GetTaggedElement(this._doc, this._tag);
     this._tagHeadPosition = this._currentView.get_CropBox().get_Transform().get_Inverse().OfPoint(tag.get_TagHeadPosition());
     this._tagHeadPosition = new XYZ(this._tagHeadPosition.get_X(), this._tagHeadPosition.get_Y(), 0.0);
     this._leaderEnd       = TagLeader.GetLeaderEnd(this._taggedElement, this._currentView);
     this._side            = XYZ.op_Division(XYZ.op_Addition(this._currentView.get_CropBox().get_Max(), this._currentView.get_CropBox().get_Min()), 2.0).get_X() <= this._leaderEnd.get_X() ? ViewSides.Right : ViewSides.Left;
     this.GetTagDimension();
 }
예제 #4
0
        public XYZ GetLeaderEnd()
        {
            XYZ     LeaderEnd = this.Center;
            Element e         = this.Parent;

            //Find the leader end, if any
            if (e.GetType() == typeof(IndependentTag))
            {
                IndependentTag tag = e as IndependentTag;
                if (tag.HasLeader)
                {
                    if (tag.LeaderEndCondition == LeaderEndCondition.Free)
                    {
                        LeaderEnd = tag.LeaderEnd;
                    }
                    else
                    {
                        Element taggedElement = TagLeader.GetTaggedElement(_doc, tag);
                        LeaderEnd = TagLeader.GetLeaderEnd(taggedElement, _ownerView);
                    }
                }
            }
            else if (e.GetType() == typeof(TextNote))
            {
                TextNote note = e as TextNote;
                if (note.LeaderCount != 0)
                {
                    LeaderEnd = note.GetLeaders().FirstOrDefault().End;
                }
            }
            else if (e.GetType().IsSubclassOf(typeof(SpatialElementTag)))
            {
                SpatialElementTag tag = e as SpatialElementTag;

                if (tag.HasLeader)
                {
                    LeaderEnd = tag.LeaderEnd;
                }
            }
            else
            {
                LeaderEnd = Center;
            }

            return(LeaderEnd);
        }
예제 #5
0
        private void ArrangeTag(UIDocument uidoc, Transaction tx)
        {
            Document doc        = uidoc.Document;
            View     activeView = doc.ActiveView;

            //Check the current view
            if (!activeView.CropBoxActive)
            {
                throw new ErrorMessageException("Please set a crop box to the view");
            }

            IEnumerable <IndependentTag> tags = from elem in new FilteredElementCollector(doc, activeView.Id).OfClass(typeof(IndependentTag)).WhereElementIsNotElementType()
                                                let type = elem as IndependentTag
                                                           where type.HasLeader == true
                                                           select type;

            tx.Start("Prepare Tags");

            //Remove all leader to find the correct tag height and width
            foreach (IndependentTag tag in tags)
            {
                tag.LeaderEndCondition = LeaderEndCondition.Free;
                tag.LeaderEnd          = tag.TagHeadPosition;
            }



            tx.Commit();
            tx.Start("Arrange Tags");

            //Create two lists of TagLeader
            List <TagLeader> leftTagLeaders  = new List <TagLeader>();
            List <TagLeader> rightTagLeaders = new List <TagLeader>();

            foreach (IndependentTag tag in tags)
            {
                TagLeader currentTag = new TagLeader(tag, doc);
                if (currentTag.Side == ViewSides.Left)
                {
                    leftTagLeaders.Add(currentTag);
                }
                else
                {
                    rightTagLeaders.Add(currentTag);
                }
            }

            //Create a list of potential location points for tag headers
            List <XYZ> leftTagHeadPoints  = CreateTagPositionPoints(activeView, leftTagLeaders, ViewSides.Left);
            List <XYZ> rightTagHeadPoints = CreateTagPositionPoints(activeView, rightTagLeaders, ViewSides.Right);

            //Sort tag by Y position
            leftTagLeaders = leftTagLeaders.OrderBy(x => x.LeaderEnd.X).ToList();
            leftTagLeaders = leftTagLeaders.OrderBy(x => x.LeaderEnd.Y).ToList();

            //place and sort
            PlaceAndSort(leftTagHeadPoints, leftTagLeaders);


            //Sort tag by Y position
            rightTagLeaders = rightTagLeaders.OrderByDescending(x => x.LeaderEnd.X).ToList();
            rightTagLeaders = rightTagLeaders.OrderBy(x => x.LeaderEnd.Y).ToList();

            //place and sort
            PlaceAndSort(rightTagHeadPoints, rightTagLeaders);

            tx.Commit();
        }