Example #1
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();
            }
        }
Example #2
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 OldTag(TagOrientation to, XYZ thp, View v, ElementId type)
 {
     TagOrientation  = to;
     TagHeadPosition = thp;
     OwnerView       = v;
     TypeId          = type;
 }
Example #4
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);
        }
        //参考 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);
        }
Example #6
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);
            }
        }
Example #7
0
        public static List <IndependentTag> TagElements(this View view, ElementId elementId_TagType, BuiltInCategory builtInCategory, bool addLeader = false, TagOrientation tagOrientation = TagOrientation.Horizontal, bool allowDuplicates = false)
        {
            if (view == null || elementId_TagType == null || elementId_TagType == ElementId.InvalidElementId)
            {
                return(null);
            }

            Document document = view.Document;

            FamilySymbol familySymbol = document.GetElement(elementId_TagType) as FamilySymbol;

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

            BuiltInCategory builtInCategory_Tag = (BuiltInCategory)familySymbol.Category.Id.IntegerValue;

            if (!builtInCategory_Tag.IsValidTagCategory(builtInCategory))
            {
                return(null);
            }

            IEnumerable <ElementId> elementIds = new FilteredElementCollector(document, view.Id).OfCategory(builtInCategory).ToElementIds();

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

            return(TagElements(view, elementId_TagType, elementIds, addLeader, tagOrientation, allowDuplicates));
        }
Example #8
0
        public static List <IndependentTag> TagElements(this View view, ElementId elementId_TagType, IEnumerable <ElementId> elementIds, bool addLeader = false, TagOrientation tagOrientation = TagOrientation.Horizontal, bool allowDuplicates = false)
        {
            if (view == null || elementId_TagType == null || elementId_TagType == ElementId.InvalidElementId)
            {
                return(null);
            }

            Document document = view.Document;

            FamilySymbol familySymbol = document.GetElement(elementId_TagType) as FamilySymbol;

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

            BuiltInCategory builtInCategory_Tag = (BuiltInCategory)familySymbol.Category.Id.IntegerValue;

            IEnumerable <ElementId> elementIds_View = new FilteredElementCollector(document, view.Id).ToElementIds();

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

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

            if (elementIds_View.Count() == 0)
            {
                return(result);
            }

            foreach (ElementId elementId in elementIds_View)
            {
                if (elementId == null || elementId == ElementId.InvalidElementId)
                {
                    continue;
                }

                if (!elementIds.Contains(elementId))
                {
                    continue;
                }

                Element element = document.GetElement(elementId);
                if (element == null)
                {
                    continue;
                }

                if (!allowDuplicates)
                {
#if Revit2017
                    IList <ElementId> elementIds_Tags = null;
#else
                    IList <ElementId> elementIds_Tags = element.GetDependentElements(new LogicalAndFilter(new ElementClassFilter(typeof(IndependentTag)), new ElementOwnerViewFilter(view.Id)));
#endif

                    if (elementIds_Tags != null && elementIds_Tags.Count != 0)
                    {
                        ElementId elementId_Tag = elementIds_Tags.ToList().Find(x => document.GetElement(x).GetTypeId() == elementId_TagType);
                        if (elementId_Tag != null)
                        {
                            continue;
                        }
                    }
                }

                if (!builtInCategory_Tag.IsValidTagCategory((BuiltInCategory)element.Category.Id.IntegerValue))
                {
                    continue;
                }

                Autodesk.Revit.DB.Location location = element.Location;
                if (location == null)
                {
                    continue;
                }

                XYZ xyz = null;
                if (location is LocationCurve)
                {
                    LocationCurve locationCurve = (LocationCurve)location;
                    Curve         curve         = locationCurve.Curve;
                    if (curve == null)
                    {
                        continue;
                    }

                    XYZ xyz_1 = curve.GetEndPoint(0);
                    XYZ xyz_2 = curve.GetEndPoint(1);
                    xyz = new XYZ((xyz_1.X + xyz_2.X) / 2, (xyz_1.Y + xyz_2.Y) / 2, (xyz_1.Z + xyz_2.Z) / 2);
                }
                else if (location is LocationPoint)
                {
                    xyz = ((LocationPoint)location).Point;
                }

                if (xyz == null)
                {
                    continue;
                }

#if Revit2017
                IndependentTag independentTag = document.Create.NewTag(view, element, addLeader, TagMode.TM_ADDBY_CATEGORY, tagOrientation, xyz);
                independentTag?.ChangeTypeId(elementId_TagType);
#elif Revit2018
                Reference      reference      = new Reference(element);
                IndependentTag independentTag = IndependentTag.Create(document, view.Id, reference, addLeader, TagMode.TM_ADDBY_CATEGORY, tagOrientation, xyz);
                independentTag?.ChangeTypeId(elementId_TagType);
#else
                Reference      reference      = new Reference(element);
                IndependentTag independentTag = IndependentTag.Create(document, elementId_TagType, view.Id, reference, addLeader, tagOrientation, xyz);
#endif

                if (independentTag != null)
                {
                    result.Add(independentTag);
                }
            }

            return(result);
        }
Example #9
0
        public static List <IndependentTag> TagElements(this Document document, IEnumerable <string> templateNames, ElementId elementId_TagType, IEnumerable <ElementId> elementIds, bool addLeader = false, TagOrientation tagOrientation = TagOrientation.Horizontal, IEnumerable <Autodesk.Revit.DB.ViewType> viewTypes = null, bool allowDuplicates = false)
        {
            if (templateNames == null || elementId_TagType == null || elementId_TagType == ElementId.InvalidElementId)
            {
                return(null);
            }

            List <View> views_All = new FilteredElementCollector(document).OfClass(typeof(View)).Cast <View>().ToList();

            List <View> views_Templates = new List <View>();
            List <View> views           = new List <View>();

            foreach (View view in views_All)
            {
                if (viewTypes != null && viewTypes.Count() != 0 && !viewTypes.Contains(view.ViewType))
                {
                    continue;
                }

                if (view.IsTemplate)
                {
                    views_Templates.Add(view);
                }
                else
                {
                    views.Add(view);
                }
            }

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

            foreach (string name in templateNames)
            {
                View view_Template = views_Templates.Find(x => x.Name == name);
                if (view_Template == null)
                {
                    continue;
                }

                List <View> views_Temp = views.FindAll(x => x.ViewTemplateId == view_Template.Id);
                if (views_Temp == null || views_Temp.Count == 0)
                {
                    continue;
                }

                List <ElementId> elementIds_DependentView = new List <ElementId>();
                foreach (View view_Temp in views_Temp)
                {
                    IEnumerable <ElementId> elementIds_DependentView_Temp = view_Temp.GetDependentViewIds();
                    if (elementIds_DependentView_Temp == null || elementIds_DependentView_Temp.Count() == 0)
                    {
                        continue;
                    }

                    elementIds_DependentView.AddRange(elementIds_DependentView_Temp);
                }

                foreach (View view in views_Temp)
                {
                    if (elementIds_DependentView.Contains(view.Id))
                    {
                        continue;
                    }

                    List <IndependentTag> independentTags = TagElements(view, elementId_TagType, elementIds, addLeader, tagOrientation, allowDuplicates);
                    if (independentTags != null && independentTags.Count != 0)
                    {
                        result.AddRange(independentTags);
                    }
                }
            }

            return(result);
        }
Example #10
0
        public void TagElement(UIDocument uidoc, Reference myRef, View view)
        {
            Document doc = uidoc.Document;

            if (myRef == null)
            {
                return;
            }

            Element e = doc.GetElement(myRef);

            Wall wall = e as Wall;

            //Creates a selection filter to dump objects in for later selection
            ICollection <ElementId> selec = new List <ElementId>();

            //Gets the bounding box of the selected wall element picked above
            BoundingBoxXYZ bb = e.get_BoundingBox(view);

            //adds a buffer to the bounding box to ensure all elements are contained within the box
            XYZ buffer = new XYZ(0.1, 0.1, 0.1);

            //creates an ouline based on the boundingbox corners of the panel and adds the buffer
            Outline outline = new Outline(bb.Min - buffer, bb.Max + buffer);

            //filters the selection by the bounding box of the selected object
            //the "true" statement inverts the selection and selects all other objects
            BoundingBoxIsInsideFilter bbfilter = new BoundingBoxIsInsideFilter(outline, false);

            //creates a new filtered element collector that filters by the active view settings
            FilteredElementCollector collector = new FilteredElementCollector(doc, view.Id);

            //collects all objects that pass through the requirements of the bbfilter
            collector.WherePasses(bbfilter);

            //adds each element that passed the bbfilter to the current selection collector
            //also checks to see if the element can be hidden

            ICollection <Element> Embeds = new List <Element>();

            foreach (Element el in collector)
            {
                if (el.Name.Contains("EM"))
                {
                    selec.Add(el.Id);
                    Embeds.Add(el);
                }
            }

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

            //Tag the wall and place it in the middle of the wall
            LocationCurve wallLoc = wall.Location as LocationCurve;

            XYZ wallStart = wallLoc.Curve.GetEndPoint(0);
            XYZ wallEnd   = wallLoc.Curve.GetEndPoint(1);
            XYZ wallMid   = wallLoc.Curve.Evaluate(0.5, true);

            using (Transaction t = new Transaction(doc, "Create Structural connection tag."))
            {
                t.Start();

                IndependentTag newTag = doc.Create.NewTag(view, wall, false, tagMode, tagorn, wallMid);
                if (newTag == null)
                {
                    throw new Exception("Create IndependentTag Failed.");
                }

                foreach (Element el in Embeds)
                {
                    LocationPoint  embedpoint = el.Location as LocationPoint;
                    XYZ            embedXyz   = embedpoint.Point;
                    IndependentTag embedTag   = doc.Create.NewTag(view, el, false, tagMode, tagorn, embedXyz);

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

                //move panel tag 15' up from bottom of panel
                newTag.Location.Move(new XYZ(0, 0, 15));

                // newTag.TagText is read-only, so we change the Type Mark type parameter to
                // set the tag text.  The label parameter for the tag family determines
                // what type parameter is used for the tag text.

                //WallType type = wall.WallType;

                //Parameter foundParameter = type.LookupParameter("Type Mark");
                //bool result = foundParameter.Set("Hello");

                // set leader mode free
                // otherwise leader end point move with elbow point

                //newTag.LeaderEndCondition = LeaderEndCondition.Free;
                //XYZ elbowPnt = wallMid + new XYZ(5.0, 5.0, 0.0);
                //newTag.LeaderElbow = elbowPnt;
                //headerPnt = wallMid + new XYZ(10.0, 10.0, 0.0);
                //newTag.TagHeadPosition = headerPnt;

                t.Commit();
            }
        }
Example #11
0
        public static IndependentTag ToRevit(this Tag tag, Document document, ConvertSettings convertSettings)
        {
            if (tag == null || document == null)
            {
                return(null);
            }

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

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

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

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

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

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

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

            Element element = Query.Find <Element>(document, integerId_Reference);

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

            if (!tag.TryGetValue(TagParameter.Leader, out bool leader))
            {
                leader = false;
            }

            TagOrientation tagOrientation = TagOrientation.Horizontal;

            if (tag.TryGetValue(TagParameter.Orientation, out string orientation))
            {
                Enum.TryParse(orientation, out tagOrientation);
            }

            Planar.Point2D point2D = tag.Location;
            if (point2D == null)
            {
                return(null);
            }

            UV uV = point2D.ToRevit();

#if Revit2017
            IndependentTag result = null;
#elif Revit2018
            IndependentTag result = IndependentTag.Create(document, view.Id, new Reference(element), leader, TagMode.TM_ADDBY_CATEGORY, tagOrientation, new XYZ(uV.U, uV.V, 0));
            result.ChangeTypeId(familySymbol.Id);
#else
            IndependentTag result = IndependentTag.Create(document, familySymbol.Id, view.Id, new Reference(element), leader, tagOrientation, new XYZ(uV.U, uV.V, 0));
#endif
            if (leader)
            {
                UV elbow = tag.Elbow?.ToRevit();
                if (elbow != null)
                {
                    result.LeaderElbow = new XYZ(elbow.U, elbow.V, 0);
                }

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

            return(result);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            while (true) //restart until user press ESC
            {
                Application app = commandData.Application.Application;
                UIDocument uidoc = commandData.Application.ActiveUIDocument;
                Document doc = uidoc.Document;
                double mmToFeet = 1.0 / 304.8;
                Reference pickedRebarRef = null;
                Reference pickedDimensionRef = null;
                try
                {
                    pickedRebarRef = uidoc.Selection.PickObject(ObjectType.Element, new RebarSelectFilter(), "Pick a Rebar, TAB to cycle, ESC to cancel.");
                    pickedDimensionRef = uidoc.Selection.PickObject(ObjectType.Element, new DimensionSelectFilter(), "Pick a Dimension, TAB to cycle, ESC to cancel.");
                }
                catch (Autodesk.Revit.Exceptions.OperationCanceledException)
                {
                    return Result.Succeeded;
                }

                //Get rebar info
                Rebar rebar = doc.GetElement(pickedRebarRef) as Rebar;
                XYZ pickedPoint = pickedRebarRef.GlobalPoint;
                int barPositionIndex = 0;
                Line rebarSegment = RebarLineNearestPickedPoint(rebar, pickedPoint, out barPositionIndex);

                //Get dimension info
                Dimension dim = doc.GetElement(pickedDimensionRef) as Dimension;

                //Get view info
                View view = doc.ActiveView;
                double viewScale = System.Convert.ToDouble(view.get_Parameter(BuiltInParameter.VIEW_SCALE).AsInteger());
                XYZ viewOrigin = view.Origin;
                XYZ viewUpDir = view.UpDirection;
                XYZ viewRightDir = view.RightDirection;
                XYZ viewDir = view.ViewDirection;
                Plane viewPlane = Plane.CreateByNormalAndOrigin(viewDir, viewOrigin);

                //Project picked point to calculate tag placement
                XYZ picketPtOnView = Utils.ProjectPointToPlane(pickedPoint, viewPlane);
                XYZ pickedPtOnDim = dim.Curve.Project(picketPtOnView).XYZPoint;
                XYZ projectDir = Line.CreateBound(picketPtOnView, pickedPtOnDim).Direction;

                //Set tag orientation
                double angleToUp = projectDir.AngleOnPlaneTo(viewUpDir, viewDir);
                bool tagAlignmentIsVertical = false;
                TagOrientation tagOrientation = TagOrientation.Horizontal;
                if ((angleToUp < 0.25 * Math.PI) || (angleToUp > 0.75 * Math.PI && angleToUp < 1.25 * Math.PI) || (angleToUp > 1.75 * Math.PI))
                {
                    tagOrientation = TagOrientation.Vertical;
                    tagAlignmentIsVertical = true;
                }

                //Set position av tag:
                XYZ tagPoint = pickedPtOnDim;
                double dotProduct = 0.0;
                if (tagAlignmentIsVertical)
                {
                    dotProduct = viewUpDir.DotProduct(projectDir);
                }
                else
                {
                    dotProduct = viewRightDir.DotProduct(projectDir);
                }

                if (dotProduct < -0.01)
                {
                    tagPoint = tagPoint.Add(projectDir.Normalize().Multiply(viewScale * mmToFeet * 50));
                }
                else
                {
                    tagPoint = tagPoint.Add(projectDir.Normalize().Multiply(viewScale * mmToFeet * 3));
                }

                // Get reference of picked rebar, this can be used to attach rebar to dimension line
                Options opt = new Options();
                opt.View = view;
                opt.ComputeReferences = true;
                opt.IncludeNonVisibleObjects = true;
                List<Line> geomLines = new List<Line>();
                GeometryElement rebarGeom = rebar.get_Geometry(opt);
                Reference rebRef = null;
                foreach (GeometryObject geomObj in rebarGeom)
                {
                    Line geomLine = geomObj as Line;
                    if (null != geomLine)
                    {
                        XYZ p = geomLine.Direction;
                        XYZ q = rebarSegment.Direction;
                        bool isParallel = p.CrossProduct(q).IsZeroLength();

                        if (isParallel == false)
                        {
                            continue;
                        }
                        XYZ endPointOfRebar = rebarSegment.GetEndPoint(1);
                        IntersectionResult ir = geomLine.Project(
                          endPointOfRebar);
                        if (ir == null)
                            continue; // end point of rebar segment is not on the reference curve.

                        if (Math.Abs(ir.Distance) != 0)
                            continue; // end point of rebar segment is not on the reference curve.
                        rebRef = geomLine.Reference;
                    }
                }

                using (Transaction t1 = new Transaction(doc, "Isolate and tag Rebar"))
                {
                    t1.Start();
                    for (int i = 0; i < rebar.NumberOfBarPositions; i++)
                    {
                        if (i == barPositionIndex)
                        {
                            rebar.SetBarHiddenStatus(doc.ActiveView, barPositionIndex, false);
                        }
                        else
                        {
                            rebar.SetBarHiddenStatus(doc.ActiveView, i, true);
                        }
                    }
                    ElementId tagId = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RebarTags).ToElementIds().FirstOrDefault();
                    IndependentTag.Create(doc, tagId, doc.ActiveView.Id, pickedRebarRef, false, tagOrientation, tagPoint);

                    //Recreate dimension with added reference:
                    if (rebRef != null)
                    {
                        ReferenceArray refArray = dim.References;
                        refArray.Append(rebRef);
                        Line dimLine = dim.Curve as Line;
                        DimensionType dimType = doc.GetElement(dim.GetTypeId()) as DimensionType;
                        doc.Create.NewDimension(doc.ActiveView, dimLine, refArray, dimType);
                        doc.Delete(dim.Id);
                    }
                    t1.Commit();
                }
            }
        }
Example #13
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.
                IndependentTag tag1 = m_docCreator.NewTag(
                    m_view, beam, leader, tagMode, tagOrientation, curve.get_EndPoint(0));
                IndependentTag tag2 = m_docCreator.NewTag(
                    m_view, beam, leader, tagMode, tagOrientation, curve.get_EndPoint(1));

                //Change the tag's object Type.
                tag1.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                tag2.ChangeTypeId(tagSymbol.FamilySymbol.Id);
                t.Commit();
            }
        }