Creates a new IndependentTag Element.
Namespace: Autodesk.Revit.Creation
Assembly: RevitAPI (in RevitAPI.dll) Version: 16.0.0.0 (16.0.0.0)
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- dbview
- Type: Autodesk.Revit.DB View
The view in which the tag is to be visible.
- elemToTag
- Type: Autodesk.Revit.DB Element
The host object of tag.
- addLeader
- Type: System Boolean
Whether there will be a leader.
- tagMode
- Type: Autodesk.Revit.DB TagMode
The mode of the tag. Add by Category, add by Multi-Category, or add by material.
- tagOrientation
- Type: Autodesk.Revit.DB TagOrientation
The orientation of the tag.
- pnt
- Type: Autodesk.Revit.DB XYZ
If not using a leader, this is the position of the tag head. If using a leader, then the tag will be placed with the default leader length as close to this input point as possible.
Return Value
If successful, an IndependentTag object is returned.Remarks
This method forms a tag relationship to the host object.
Examples

private IndependentTag CreateIndependentTag(Autodesk.Revit.DB.Document document, Wall wall)
{
// make sure active view is not a 3D view
Autodesk.Revit.DB.View view = document.ActiveView;
// define tag mode and tag orientation for new tag
TagMode tagMode = TagMode.TM_ADDBY_CATEGORY;
TagOrientation tagorn = TagOrientation.Horizontal;
// Add the tag to 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);
IndependentTag newTag = document.Create.NewTag(view, wall, true, tagMode, tagorn, wallMid);
if (null == newTag)
{
throw new Exception("Create IndependentTag Failed.");
}
// 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;
XYZ headerPnt = wallMid + new XYZ(10.0, 10.0, 0.0);
newTag.TagHeadPosition = headerPnt;
return newTag;
}

Private Function CreateIndependentTag(document As Autodesk.Revit.DB.Document, wall As Wall) As IndependentTag
' make sure active view is not a 3D view
Dim view As Autodesk.Revit.DB.View = document.ActiveView
' define tag mode and tag orientation for new tag
Dim tagMode__1 As TagMode = TagMode.TM_ADDBY_CATEGORY
Dim tagorn As TagOrientation = TagOrientation.Horizontal
' Add the tag to the middle of the wall
Dim wallLoc As LocationCurve = TryCast(wall.Location, LocationCurve)
Dim wallStart As XYZ = wallLoc.Curve.GetEndPoint(0)
Dim wallEnd As XYZ = wallLoc.Curve.GetEndPoint(1)
Dim wallMid As XYZ = wallLoc.Curve.Evaluate(0.5, True)
Dim newTag As IndependentTag = document.Create.NewTag(view, wall, True, tagMode__1, tagorn, wallMid)
If newTag Is Nothing Then
Throw New Exception("Create IndependentTag Failed.")
End If
' 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.
Dim type As WallType = wall.WallType
Dim foundParameter As Parameter = type.LookupParameter("Type Mark")
Dim result As Boolean = foundParameter.[Set]("Hello")
' set leader mode free
' otherwise leader end point move with elbow point
newTag.LeaderEndCondition = LeaderEndCondition.Free
Dim elbowPnt As XYZ = wallMid + New XYZ(5.0, 5.0, 0.0)
newTag.LeaderElbow = elbowPnt
Dim headerPnt As XYZ = wallMid + New XYZ(10.0, 10.0, 0.0)
newTag.TagHeadPosition = headerPnt
Return newTag
End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.Exceptions InvalidOperationException | If the view is a perspective view. |
Autodesk.Revit.Exceptions ArgumentException | Thrown if the element to tag does not exist in the given document. |
Autodesk.Revit.Exceptions ArgumentException | Thrown if the view does not exist in the given document. |