//ToDo: genericize this, so that it allows common settings for all tags, then unique settings as needed per tag
        public static List <IndependentTag> CreateTags(View view, FamilySymbol tagSymbol)
        {
            if (tagSymbol == null || tagSymbol.Category == null)
            {
                return(null);
            }

            Document _doc = view.Document;

            List <FamilyInstance> _reshores = new FilteredElementCollector(_doc).OfClass(typeof(FamilyInstance)).OfType <FamilyInstance>().ToList();

            TagMode _tagMode = tagSymbol.Category.Id.IntegerValue == (int)BuiltInCategory.OST_MultiCategoryTags
                ? TagMode.TM_ADDBY_MULTICATEGORY
                : TagMode.TM_ADDBY_CATEGORY;

            List <IndependentTag> _tags = new List <IndependentTag>();

            foreach (FamilyInstance _reshore in _reshores)
            {
                BoundingBoxXYZ _boundingBoxXYZ = _reshore.get_BoundingBox(null);

                XYZ _tagHeadCoordinate = (_boundingBoxXYZ.Min + _boundingBoxXYZ.Max) / 2.0;

                Reference _reference = new Reference(_reshore);

                IndependentTag _tag = IndependentTag.Create(_doc, view.Id, _reference, true, _tagMode, TagOrientation.Horizontal, _tagHeadCoordinate);
                _tags.Add(_tag);
            }
            return(_tags);
        }
Exemplo n.º 2
0
        public TagLeader(IndependentTag tag, Document doc)
        {
            _doc         = doc;
            _currentView = _doc.GetElement(tag.OwnerViewId) as View;
            _tag         = tag;

            _taggedElement   = GetTaggedElement(_doc, _tag);
            _tagHeadPosition = _currentView.CropBox.Transform.Inverse.OfPoint(tag.TagHeadPosition);
            _tagHeadPosition = new XYZ(_tagHeadPosition.X, _tagHeadPosition.Y, 0);
            _leaderEnd       = GetLeaderEnd(_taggedElement, _currentView);

            //View center
            XYZ viewCenter = (_currentView.CropBox.Max + _currentView.CropBox.Min) / 2;

            if (viewCenter.X > _leaderEnd.X)
            {
                _side = ViewSides.Left;
            }
            else
            {
                _side = ViewSides.Right;
            }

            GetTagDimension();
        }
Exemplo n.º 3
0
        //method to find the tagged element using the reference
        public static bool GetTaggedElement(UIDocument m_doc, Reference LocalRef, int num)
        {
            startNumber = num;
            IndependentTag selectedTag   = null;
            Element        taggedElement = null;

            //make sure that the ref is not null
            if (LocalRef != null)
            {
                //check if the element selected is of type independent tag
                if (m_doc.Document.GetElement(LocalRef) is IndependentTag)
                {
                    selectedTag = (IndependentTag)m_doc.Document.GetElement(LocalRef);

                    //find the element which is tagged by the selected tag
                    taggedElement = selectedTag.GetTaggedLocalElement();

                    //call to the change mark value method
                    if (MarkValue(taggedElement))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
        protected override Result ProcessCommand(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // Tag All Door

            var listCategory = new List <BuiltInCategory>()
            {
                BuiltInCategory.OST_Doors, BuiltInCategory.OST_Windows
            };

            var filter       = new ElementMulticategoryFilter(listCategory);
            var elementLists = new FilteredElementCollector(_activeDocument, _activeDocument.ActiveView.Id)
                               .WherePasses(filter)
                               .WhereElementIsNotElementType()
                               .ToElements();

            using (Transaction trans = new Transaction(_activeDocument, "Create View Plan"))
            {
                trans.Start();
                foreach (var element in elementLists)
                {
                    var reference = new Reference(element);
                    var loc       = element.Location as LocationPoint;
                    var pos       = loc.Point;
                    var tagNode   = IndependentTag.Create(_activeDocument, _activeDocument.ActiveView.Id, reference, true, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, pos);
                }
                trans.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 5
0
        private void CreateNewTagForPointLoad(View activeV, XYZ loadPosition, PointLoad pl)
        {
            Transaction t = new Transaction(_doc);

            t.Start("Create tag for point load");
            TagMode        tagMode = TagMode.TM_ADDBY_CATEGORY;
            TagOrientation tagorn  = TagOrientation.Horizontal;

            IndependentTag tag     = IndependentTag.Create(_doc, activeV.Id, new Reference(pl), false, tagMode, tagorn, loadPosition);
            FamilySymbol   tagType =
                (from fs in new FilteredElementCollector(_doc)
                 .OfCategory(BuiltInCategory.OST_PointLoadTags)
                 .OfClass(typeof(FamilySymbol))
                 .Cast <FamilySymbol>()
                 where fs.Name.Equals(Default.TYPE_NAME_POINT_LOAD)
                 select fs)
                .FirstOrDefault();

            if (tagType != null)
            {
                tag.ChangeTypeId(tagType.Id);
            }
            t.Commit();
            AssociateTagToPointLoad(pl, tag);
        }
        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);
        }
        //参考 https://stackoverflow.com/questions/25457886/c-sharp-revit-api-createindependenttag-method-failing-to-add-tag-to-ceilings-e
        public IndependentTag CreateOneFloorIndependentTag(Document document, Floor floor, string labelName)
        {
            Autodesk.Revit.DB.View view = document.ActiveView;

            TagMode        tagMode = TagMode.TM_ADDBY_CATEGORY;
            TagOrientation tagOri  = TagOrientation.Horizontal;

            //Revit elements can be located by a point(most family instance),a line(walls, line based components)
            //or sketch(celling, floors etc);
            //Simply answer is to find the boundling of box of the floor and calculate the center of the
            //if the floor is a large L shape or something the boundling box center may not be over the floor at all
            //need some other algorithm to find the center point;

            //calculate the center of mark
            XYZ centerPoint = CalculateCenterOfMark(floor, view);

            IndependentTag newTag = document.Create.NewTag(view, floor, false, tagMode, tagOri, centerPoint);

            if (null == newTag)
            {
                throw new Exception("Create IndependentTag Failed!");
            }
            //NewTag.tagText is read-only, so use the othter parameters to set the tag text;
            SetTagText(floor, labelName);
            return(newTag);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Tag the beam's start and end.
        /// </summary>
        /// <param name="tagMode">Mode of tag</param>
        /// <param name="tagSymbol">Tag symbol wrapper</param>
        /// <param name="leader">Whether the tag has leader</param>
        /// <param name="tagOrientation">Orientation of tag</param>
        public void CreateTag(TagMode tagMode,
                              FamilySymbolWrapper tagSymbol, bool leader,
                              TagOrientation tagOrientation)
        {
            foreach (FamilyInstance beam in m_beamList)
            {
                //Get the start point and end point of the selected beam.
                Autodesk.Revit.DB.LocationCurve location = beam.Location as Autodesk.Revit.DB.LocationCurve;
                Autodesk.Revit.DB.Curve         curve    = location.Curve;

                Transaction t = new Transaction(m_revitDoc.Document);
                t.Start("Create new tag");
                //Create tag on the beam's start and end.
                Reference      beamRef = new Reference(beam);
                IndependentTag tag1    = IndependentTag.Create(m_revitDoc.Document,
                                                               m_view.Id, beamRef, leader, tagMode, tagOrientation, curve.GetEndPoint(0));
                IndependentTag tag2 = IndependentTag.Create(m_revitDoc.Document,
                                                            m_view.Id, beamRef, leader, tagMode, tagOrientation, curve.GetEndPoint(1));

                //Change the tag's object Type.
                tag1.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                tag2.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                t.Commit();
            }
        }
Exemplo n.º 9
0
        private void AssociateTagToPointLoad(PointLoad pl, IndependentTag tag)
        {
            using (Transaction trans = new Transaction(_doc, "Create Extensible Store"))
            {
                trans.Start();

                SchemaBuilder builder = new SchemaBuilder(Guids.POINTLOAD_SHEMA_GUID);

                builder.SetReadAccessLevel(AccessLevel.Public);
                builder.SetWriteAccessLevel(AccessLevel.Public);

                builder.SetSchemaName("Tag");

                builder.SetDocumentation("The tag linked to the point load");

                // Create field1
                FieldBuilder fieldBuilder1 = builder.AddSimpleField("Tag", typeof(ElementId));

                // Register the schema object
                Schema schema = builder.Finish();

                Field  tagField = schema.GetField("Tag");
                Entity ent      = new Entity(schema);

                ent.Set(tagField, tag.Id);
                pl.SetEntity(ent);

                trans.Commit();
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// https://thebuildingcoder.typepad.com/blog/2010/06/set-tag-type.html
        /// </summary>
        /// <param name="document"></param>
        /// <param name="column"></param>
        /// <param name="viewId"></param>
        /// <returns></returns>
        private IndependentTag CreateIndependentTagColumn(Document document, FamilyInstance column, ElementId viewId, double Xoffset)
        {
            View view = document.GetElement(viewId) as View;

            // define tag mode and tag orientation for new tag
            TagMode        tagMode        = TagMode.TM_ADDBY_CATEGORY;
            TagOrientation tagorientation = TagOrientation.Horizontal;

            // Add the tag to the middle of the colunm
            Reference columnRef = new Reference(column);

            BoundingBoxXYZ bbox = column.get_BoundingBox(view);

            XYZ centroid = new XYZ((bbox.Max.X + bbox.Min.X) / 2, (bbox.Max.Y + bbox.Min.Y) / 2, (bbox.Max.Z + bbox.Min.Z) / 2);

            XYZ position = centroid + new XYZ(Xoffset, 0, 0);

            IndependentTag newTag = document.Create.NewTag(view, column, false, tagMode, tagorientation, position);

            if (null == newTag)
            {
                throw new Exception("Create IndependentTag Failed.");
            }

            return(newTag);
        }
Exemplo n.º 11
0
        private List <AnnotationElement> RetriveAnnotationElementsFromSelection(UIDocument UIDoc, Transaction tx)
        {
            ICollection <ElementId>  elementIds            = UIDoc.Selection.GetElementIds();
            List <Element>           elementList           = new List <Element>();
            List <AnnotationElement> annotationElementList = new List <AnnotationElement>();

            tx.Start("Prepare tags");
            using (IEnumerator <ElementId> enumerator = ((IEnumerable <ElementId>)elementIds).GetEnumerator())
            {
                while (((IEnumerator)enumerator).MoveNext())
                {
                    ElementId current = enumerator.Current;
                    Element   element = UIDoc.get_Document().GetElement(current);
                    if (((object)element).GetType() == typeof(IndependentTag))
                    {
                        IndependentTag independentTag = element as IndependentTag;
                        independentTag.set_LeaderEndCondition((LeaderEndCondition)1);
                        if (independentTag.get_HasLeader())
                        {
                            independentTag.set_LeaderEnd(independentTag.get_TagHeadPosition());
                            independentTag.set_LeaderElbow(independentTag.get_TagHeadPosition());
                        }
                        elementList.Add(element);
                    }
                    else if (((object)element).GetType() == typeof(TextNote))
                    {
                        (element as TextNote).RemoveLeaders();
                        elementList.Add(element);
                    }
                    else if (((object)element).GetType().IsSubclassOf(typeof(SpatialElementTag)))
                    {
                        SpatialElementTag spatialElementTag = element as SpatialElementTag;
                        if (spatialElementTag.get_HasLeader())
                        {
                            spatialElementTag.set_LeaderEnd(spatialElementTag.get_TagHeadPosition());
                            spatialElementTag.set_LeaderElbow(spatialElementTag.get_TagHeadPosition());
                        }
                        elementList.Add(element);
                    }
                    else
                    {
                        elementList.Add(element);
                    }
                }
            }
            FailureHandlingOptions failureHandlingOptions = tx.GetFailureHandlingOptions();

            failureHandlingOptions.SetFailuresPreprocessor((IFailuresPreprocessor) new CommitPreprocessor());
            tx.Commit(failureHandlingOptions);
            using (List <Element> .Enumerator enumerator = elementList.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Element current = enumerator.Current;
                    annotationElementList.Add(new AnnotationElement(current));
                }
            }
            return(annotationElementList);
        }
Exemplo n.º 12
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication           uiapp        = commandData.Application;
            UIDocument              uidoc        = uiapp.ActiveUIDocument;
            Application             app          = uiapp.Application;
            Document                doc          = uidoc.Document;
            Selection               SelectedObjs = uidoc.Selection;
            ICollection <ElementId> newSel       = new List <ElementId>();
            ICollection <ElementId> ids          = uidoc.Selection.GetElementIds();

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Create Tags");
                bool start  = true;
                XYZ  tagpos = new XYZ(0, 0, 0);
                foreach (ElementId eid in ids)
                {
                    Element        elem   = doc.GetElement(eid);
                    Reference      tagref = new Reference(elem);
                    IndependentTag tag    = null;
                    if (elem.Category.Name.Contains("Tags"))
                    {
                        tag = elem as IndependentTag;
                        if (start)
                        {
                            tagpos = tag.TagHeadPosition;
                            start  = false; newSel.Add(tag.Id);
                        }
                        else
                        {
                            tag.TagHeadPosition = tagpos; newSel.Add(tag.Id);
                        }
                    }
                    else
                    {
                        LocationCurve refline = elem.Location as LocationCurve;
                        tag = IndependentTag.Create(doc, doc.ActiveView.Id, tagref, true, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, refline.Curve.Evaluate(0.5, true));

                        if (start)
                        {
                            tagpos = tag.TagHeadPosition;
                            start  = false;
                            newSel.Add(tag.Id);
                        }
                        else
                        {
                            tag.TagHeadPosition = tagpos; newSel.Add(tag.Id);
                        }
                    }
                }
                uidoc.Selection.SetElementIds(newSel);
                tx.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication           uiapp        = commandData.Application;
            UIDocument              uidoc        = uiapp.ActiveUIDocument;
            Application             app          = uiapp.Application;
            Document                doc          = uidoc.Document;
            Selection               SelectedObjs = uidoc.Selection;
            ICollection <ElementId> ids          = uidoc.Selection.GetElementIds();
            List <IndependentTag>   prevtags     = new List <IndependentTag>();

            // Menu Values have to be acquired from Ribbon.
            RackDim.GetMenuValues(uiapp);

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Merge Tags");
                bool start  = true;
                bool fits   = false;
                XYZ  tagpos = new XYZ(0, 0, 0);
                foreach (ElementId eid in ids)
                {
                    Element        elem = doc.GetElement(eid);
                    IndependentTag tag  = elem as IndependentTag;
                    if (start)
                    {
                        tagpos = tag.TagHeadPosition;
                        start  = false;
                        prevtags.Add(tag);
                    }
                    else
                    {
                        fits = false;
                        foreach (IndependentTag ptag in prevtags)
                        {
                            if (fits == false &&
                                ptag.TagText == tag.TagText &&
                                Math.Abs(ptag.TagHeadPosition.X - tag.TagHeadPosition.X) < Store.mod_left &&
                                Math.Abs(ptag.TagHeadPosition.Y - tag.TagHeadPosition.Y) < Store.mod_right)
                            {
                                tag.TagHeadPosition = ptag.TagHeadPosition;
                                fits = true;
                            }
                        }
                        if (!fits)
                        {
                            prevtags.Add(tag);
                        }
                    }
                }
                tx.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 15
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();
        }
Exemplo n.º 16
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();
 }
Exemplo n.º 17
0
        private void ListRevInfo2(IList <Element> revTags)
        {
            int i = 0;

            logMsg(nl);
            logMsgDbLn2("revision tags");

            IList <string[]> RevisionInfo = new List <string[]>(revTags.Count);


            foreach (Element e in revTags)
            {
                string[] ri = new string[(int)REV_LEN];


                i++;
                IndependentTag revTag   = e as IndependentTag;
                RevisionCloud  revCloud = revTag.GetTaggedLocalElement() as RevisionCloud;
                Revision       rev      =
                    Doc.GetElement(revCloud.get_Parameter(BuiltInParameter.REVISION_CLOUD_REVISION).AsElementId()) as Revision;

                // show only visible revisions
                if (rev != null && RevisionVisible[rev.SequenceNumber])
                {
//					ParameterSet psrt = revTag.Parameters;
//					ParameterSet ps = revCloud.Parameters;
//					IList<Parameter> po = revCloud.GetOrderedParameters();
                    ISet <ElementId> s = revCloud.GetSheetIds();

                    // get the sheet number
                    foreach (ElementId ex in s)
                    {
                        //						ri[(int) REV_SHTNUM] = ((ViewSheet) _doc.GetElement(ex)).SheetNumber;
                        logMsgDbLn2("sheet number", ((ViewSheet)Doc.GetElement(ex)).SheetNumber);
                    }

                    string num = i.ToString();


                    logMsgDbLn2("tag rev seq| " + num, rev.SequenceNumber);

                    logMsgDbLn2("revision title| " + num, revCloud.get_Parameter(BuiltInParameter.REVISION_CLOUD_REVISION_DESCRIPTION).AsString());
                    logMsgDbLn2("revision id| " + num, revCloud.get_Parameter(BuiltInParameter.REVISION_CLOUD_REVISION_NUM).AsString());
                    logMsgDbLn2("revision alt id| " + num, revCloud.get_Parameter(BuiltInParameter.REVISION_CLOUD_REVISION_ISSUED_BY).AsString());
                    logMsgDbLn2("revision date| " + num, revCloud.get_Parameter(BuiltInParameter.REVISION_CLOUD_REVISION_DATE).AsString());

                    logMsgDbLn2("revision desc 1?| " + num, revCloud.get_Parameter(BuiltInParameter.ALL_MODEL_MARK)?.AsString() ?? "null");

                    logMsgDbLn2("revision basis 1?| " + num, revCloud.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS)?.AsString() ?? "null");
                }
            }
        }
Exemplo n.º 18
0
 private void Initialize()
 {
     _mark = (IndependentTag)_selector.PickElementByClass <IndependentTag>();
     if (_mark == null)
     {
         TaskDialog.Show("Ошибка", "Выбрана не марка");
     }
     else
     {
         elementCategory = _doc.GetElement(_mark.TaggedElementId.HostElementId).Category;
         midle           = _mark.LeaderElbow;
         head            = _mark.TagHeadPosition;
         point           = _mark.LeaderEnd;
     }
 }
Exemplo n.º 19
0
        public static string TagText(global::Revit.Elements.Element tag)
        {
            var    internalTag  = tag.InternalElement;
            string internalType = internalTag.GetType().BaseType.Name;

            if (internalType.Equals("SpatialElementTag"))
            {
                Autodesk.Revit.DB.SpatialElementTag spatialTag = internalTag as Autodesk.Revit.DB.SpatialElementTag;
                return(spatialTag.TagText);
            }

            IndependentTag independentTag = internalTag as IndependentTag;

            return(independentTag.TagText);
        }
Exemplo n.º 20
0
 public ElementFindclass(Document doc, IndependentTag independentTag, List<ViewSheet> listsheet)
 {
     bool flag = independentTag == null || independentTag.OwnerViewId == ElementId.InvalidElementId;
     if (!flag)
     {
         var viewid = independentTag.OwnerViewId;
         foreach (var i in listsheet)
         {
             var allviewonsheet = i.GetAllPlacedViews();
             foreach (var item in allviewonsheet)
             {
                 if (item == viewid)
                 {
                     Sheet = i;
                     Element element = independentTag.GetTaggedLocalElement();
                     Autodesk.Revit.DB.Parameter parameter = (element != null) ? element.LookupParameter("CONTROL_NUMBER") : null;
                     Autodesk.Revit.DB.Parameter parameter2 = (element != null) ? element.LookupParameter("CONTROL_MARK") : null;
                     bool flag4 = parameter == null || parameter.StorageType != StorageType.String;
                     if (!flag4)
                     {
                         bool flag5 = parameter2 == null || parameter2.StorageType != StorageType.String;
                         if (!flag5)
                         {
                             Control_mark = parameter2.AsString();
                             Control_Number = parameter.AsString();
                             SheetName = Sheet.Name;
                             Sheetnumber = Sheet.SheetNumber;
                             ViewName = doc.GetElement(viewid).Name;
                             ID = element.Id;
                         }
                     }
                     else
                     {
                         bool flag5 = parameter2 == null || parameter2.StorageType != StorageType.String;
                         if (!flag5)
                         {
                             Control_mark = parameter2.AsString();
                             Control_Number = "";
                             SheetName = Sheet.Name;
                             Sheetnumber = Sheet.SheetNumber;
                             ViewName = doc.GetElement(viewid).Name;
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 21
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            // get UIdocument
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            //get document
            Document doc = uidoc.Document;

            //Tag parameters
            TagMode        tmode   = TagMode.TM_ADDBY_CATEGORY;
            TagOrientation torient = TagOrientation.Horizontal;

            List <BuiltInCategory> cats = new List <BuiltInCategory>();

            cats.Add(BuiltInCategory.OST_Windows);
            cats.Add(BuiltInCategory.OST_Doors);

            ElementMulticategoryFilter filter    = new ElementMulticategoryFilter(cats);
            IList <Element>            telements = new FilteredElementCollector(doc, doc.ActiveView.Id)
                                                   .WherePasses(filter)
                                                   .WhereElementIsNotElementType()
                                                   .ToElements();

            try
            {
                using (Transaction trans = new Transaction(doc, "create plan view"))
                {
                    trans.Start();
                    // tag elements
                    foreach (Element ele in telements)
                    {
                        Reference      refe  = new Reference(ele);
                        LocationPoint  loc   = ele.Location as LocationPoint;
                        XYZ            point = loc.Point;
                        IndependentTag tag   = IndependentTag.Create(doc, doc.ActiveView.Id, refe, true, tmode, torient, point);
                    }
                    trans.Commit();
                }

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Result.Failed);
            }
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
        public static Element GetTaggedElement(Document doc, IndependentTag tag)
        {
            Element taggedElement;

            if (tag.TaggedElementId.HostElementId == ElementId.InvalidElementId)
            {
                RevitLinkInstance linkInstance   = doc.GetElement(tag.TaggedElementId.LinkInstanceId) as RevitLinkInstance;
                Document          linkedDocument = linkInstance.GetLinkDocument();

                taggedElement = linkedDocument.GetElement(tag.TaggedElementId.LinkedElementId);
            }
            else
            {
                taggedElement = doc.GetElement(tag.TaggedElementId.HostElementId);
            }

            return(taggedElement);
        }
Exemplo n.º 24
0
        /// <summary>
        /// 给图元注释标记族,默认位置为Boundingbox的Min,注释数据为图元实例标记值,是否显示引线(0-否,1-是)
        /// </summary>
        public static void SetTag(this View view, Document doc, Element element, ElementId TagFamilySymbolId, int isHadLEADER_LINE)
        {
            string field = element.get_Parameter(BuiltInParameter.DOOR_NUMBER).AsString();

            if (field == null || field == "")
            {
            }
            else
            {
                BoundingBoxXYZ boundingBoxXYZ = element.get_BoundingBox(view);
                if (boundingBoxXYZ != null)
                {
                    XYZ            min            = element.get_BoundingBox(view).Min;
                    XYZ            max            = element.get_BoundingBox(view).Max;
                    XYZ            middleEleXYZ   = (min + max) / 2;
                    IndependentTag independentTag = IndependentTag.Create(doc, TagFamilySymbolId, view.Id, new Reference(element), true, TagOrientation.Horizontal, min);
                    // 是否 取消标记引线
                    independentTag.get_Parameter(BuiltInParameter.LEADER_LINE).Set(isHadLEADER_LINE);
                }
            }
        }
Exemplo n.º 25
0
        public Autodesk.Revit.UI.Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                // Get the active document and view
                UIDocument             revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view     = revitDoc.Document.ActiveView;
                foreach (ElementId elemId in revitDoc.Selection.GetElementIds())
                {
                    Element elem = revitDoc.Document.GetElement(elemId);
                    if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar))
                    {
                        // cast to Rebar and get its first curve
                        Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem;
                        Autodesk.Revit.DB.Curve           curve = rebar.GetCenterlineCurves(false, false, false)[0];

                        // create a rebar tag at the first end point of the first curve
                        using (Transaction t = new Transaction(revitDoc.Document))
                        {
                            t.Start("Create new tag");
                            IndependentTag tag = revitDoc.Document.Create.NewTag(view, rebar, true,
                                                                                 Autodesk.Revit.DB.TagMode.TM_ADDBY_CATEGORY,
                                                                                 Autodesk.Revit.DB.TagOrientation.Horizontal, curve.GetEndPoint(0));
                            t.Commit();
                        }
                        return(Autodesk.Revit.UI.Result.Succeeded);
                    }
                }
                message = "No rebar selected!";
                return(Autodesk.Revit.UI.Result.Failed);
            }
            catch (Exception e)
            {
                message = e.Message;
                return(Autodesk.Revit.UI.Result.Failed);
            }
        }
Exemplo n.º 26
0
        //Tag by hand example
        public void tagMultiRebar_GetSubelement()
        {
            UIDocument uiDoc = this.ActiveUIDocument;

            Document doc = uiDoc.Document;


            View myView = doc.ActiveView;



            Reference myRefMRA             = uiDoc.Selection.PickObject(ObjectType.Element, "Pick MRA...");
            MultiReferenceAnnotation myMRA = doc.GetElement(myRefMRA) as MultiReferenceAnnotation;


            TaskDialog.Show("abc", "TagId: " + myMRA.TagId.ToString());

            IndependentTag myTag_2 = doc.GetElement(myMRA.TagId) as IndependentTag;


//			Reference myRefTag = uiDoc.Selection.PickObject(ObjectType.Element, "Pick MRA...");
//			IndependentTag myTag= doc.GetElement(myRefTag) as IndependentTag;
            setCurrentViewAsWorkPlan();
            XYZ pointPicked = uiDoc.Selection.PickPoint("Pick a Point...");


            using (Transaction tran = new Transaction(doc))
            {
                tran.Start("Nove_tag");



//			ElementTransformUtils.MoveElement(doc, myTag.Id, new XYZ(1,1,0));
                myTag_2.TagHeadPosition = new XYZ(pointPicked.X, pointPicked.Y, myTag_2.TagHeadPosition.Z);


                tran.Commit();
            }
        }
Exemplo n.º 27
0
        internal bool Generate(PBPAModel model)
        {
            Document doc  = model.Document;
            View     view = doc.GetElement(model.ViewId) as View;

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

            //主体
            var target         = doc.GetElement(model.TargetId);
            var targetLocation = target.Location as LocationCurve;
            var p0             = targetLocation.Curve.GetEndPoint(0);
            var p1             = targetLocation.Curve.GetEndPoint(1);
            var pMiddle        = new XYZ((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2, (p0.Z + p1.Z) / 2);

            model.TargetLocation = pMiddle;
            //线生成
            List <Line> lines = new List <Line>();

            model.CalculateLocations();                                            //计算内容定位
            lines.Add(Line.CreateBound(model.BodyStartPoint, model.BodyEndPoint)); //竖干线
            lines.Add(Line.CreateBound(model.BodyEndPoint, model.LeafEndPoint));   //斜支线
            model.LineIds = new List <ElementId>();
            foreach (var line in lines)
            {
                var lineElement = doc.Create.NewDetailCurve(view, line);
                model.LineIds.Add(lineElement.Id);
            }
            //文本生成
            IndependentTag subTag = doc.Create.NewTag(view, doc.GetElement(model.TargetId), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, model.AnnotationLocation);

            model.AnnotationId     = subTag.Id;
            subTag.TagHeadPosition = model.AnnotationLocation;
            subTag.ChangeTypeId(model.GetAnnotationFamily(doc, model.TargetId).Id);
            return(true);
        }
Exemplo n.º 28
0
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
 {
     Application app = commandData.Application.Application;
     UIDocument uidoc = commandData.Application.ActiveUIDocument;
     Document doc = uidoc.Document;
     ElementId elementId1 = uidoc.Selection.GetElementIds().FirstOrDefault();
     if (elementId1 == null)
     {
         TaskDialog.Show("Warning", "Select a tag before running this command");
         return Result.Failed;
     }
     IndependentTag selectedTag = doc.GetElement(elementId1) as IndependentTag;
     if (selectedTag == null)
     {
         TaskDialog.Show("Warning", "Select a tag before running this command");
         return Result.Failed;
     }
     Transaction t1 = new Transaction(doc,"Tag Leader Cycle");
     t1.Start();
     if (selectedTag.HasLeader == true)
     {
         if (selectedTag.LeaderEndCondition == LeaderEndCondition.Free)
         {
             selectedTag.LeaderEndCondition = LeaderEndCondition.Attached;
         }
         else
         {
             selectedTag.HasLeader = false;
         }
     }
     else
     {
         selectedTag.HasLeader = true;
         selectedTag.LeaderEndCondition = LeaderEndCondition.Free;
     }
     t1.Commit();
     return Result.Succeeded;
 }
Exemplo n.º 29
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication           uiapp        = commandData.Application;
            UIDocument              uidoc        = uiapp.ActiveUIDocument;
            Application             app          = uiapp.Application;
            Document                doc          = uidoc.Document;
            Selection               SelectedObjs = uidoc.Selection;
            ICollection <ElementId> ids          = uidoc.Selection.GetElementIds();
            ICollection <ElementId> newsel       = new List <ElementId>();

            RackDim.GetMenuValues(uiapp);
            string contains = "Round";

            if (Store.place_ib.Value as string != null)
            {
                contains = "Rectangular";
            }
            foreach (ElementId eid in ids)
            {
                IndependentTag tag        = doc.GetElement(eid) as IndependentTag;
                string         familyname = tag.GetTaggedLocalElement().get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString();
                if (familyname.Contains(contains))
                {
                    newsel.Add(eid);
                }
            }
            using (Transaction trans = new Transaction(doc))
            {
                trans.Start("Select tags");
                uidoc.Selection.SetElementIds(newsel);
                trans.Commit();
            }
            return(Result.Succeeded);
        }
Exemplo n.º 30
0
        private static bool GenerateSingle_LeftOrMiddle(PAAModel model)
        {
            Document doc    = model.Document;
            View     view   = doc.ActiveView;
            var      target = doc.GetElement(model.TargetId);
            var      line   = (target.Location as LocationCurve).Curve as Line;

            model.UpdateVectors(line);
            var p0 = line.GetEndPoint(0);
            var p1 = line.GetEndPoint(1);

            switch (model.TextType)
            {
            case PAATextType.Option1:
                var location = (p0 + p1) / 2;
                model.UpdateLineWidth(target);
                location = location - model.LineWidth / 2 * model.ParallelVector;
                IndependentTag subTag = doc.Create.NewTag(view, doc.GetElement(model.TargetId), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, location);
                subTag.ChangeTypeId(model.GetAnnotationFamily(doc, model.TargetId).Id);
                break;

            case PAATextType.Option2:
                //location = p0.GetLengthBySide(model.ParallelVector) > p1.GetLengthBySide(model.ParallelVector) ? p1 : p0;//左上角
                location = (p0 + p1) / 2;
                model.UpdateLineWidth(target);
                location  = location - model.LineWidth / 2 * model.ParallelVector;
                location += model.CurrentFontHeight * model.VerticalVector;
                subTag    = doc.Create.NewTag(view, doc.GetElement(model.TargetId), false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, location);
                subTag.ChangeTypeId(model.GetAnnotationFamily(doc, model.TargetId).Id);
                break;

            default:
                break;
            }
            return(false);
        }
Exemplo n.º 31
0
        private void Stream( ArrayList data, IndependentTag tag )
        {
            data.Add( new Snoop.Data.ClassSeparator( typeof( IndependentTag ) ) );

              try
              {
            data.Add( new Snoop.Data.Xyz( "Leader elbow", tag.LeaderElbow ) );
              }
              catch( Exception ex )
              {
            data.Add( new Snoop.Data.Exception( "Leader elbow", ex ) );
              }

              try
              {
            data.Add( new Snoop.Data.Xyz( "Leader end", tag.LeaderEnd ) );
              }
              catch( Exception ex )
              {
            data.Add( new Snoop.Data.Exception( "Leader end", ex ) );
              }

              data.Add( new Snoop.Data.String( "Tag orientation", tag.TagOrientation.ToString() ) );
              data.Add( new Snoop.Data.Xyz( "Tag head position", tag.TagHeadPosition ) );
              data.Add( new Snoop.Data.ElementId( "TaggedLocalElementId", tag.TaggedLocalElementId, tag.Document ) );
              try
              {
            if( tag.TagText != null ) data.Add( new Snoop.Data.String( "Tag text", tag.TagText ) );
              }
              catch( Exception ex )
              {
            data.Add( new Snoop.Data.Exception( "Tag text", ex ) );
              }
        }