2027 Method
Changes 0
M

IndependentTag.Create

Description:
Places a tag on an element or subelement.
Remarks:
Single category tags, multi-category tags and material tags can be placed.
Overloads (2):
Create(Document,ElementId,Reference,Boolean,TagMode,TagOrientation,XYZ)
public static IndependentTag Create(
	Document document,
	ElementId ownerDBViewId,
	Reference referenceToTag,
	bool addLeader,
	TagMode tagMode,
	TagOrientation tagOrientation,
	XYZ pnt
)
  • document
    The document to which the tag will be added.
  • ownerDBViewId
    The view in which the tag will be visible.
  • referenceToTag
    The host reference of the tag. The reference can be to an element or subelement in a local or linked document.
  • Boolean
    addLeader
    When true, the tag will be created with a straight leader with an attached end.
  • tagMode
    This argument determines the type of tag that will be created. Tag by category, multi-category tag, and material tag are allowed.
  • tagOrientation
    The orientation of the tag's head.
  • pnt
    For tags without leaders, this point is the position of the tag head. For tags with leaders, this point is the end point of the leader, and a leader of default length will be created from this point to the tag head.
Return Value IndependentTag If successful the new tag is returned.
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);
    Reference wallRef = new Reference(wall);

    IndependentTag newTag = IndependentTag.Create(document, view.Id,  wallRef, 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.SetLeaderElbow(wallRef, elbowPnt);
    XYZ headerPnt = wallMid + new XYZ(10.0, 10.0, 0.0);
    newTag.TagHeadPosition = headerPnt;

    // change tag orientation to AnyModelDirection
    newTag.TagOrientation = TagOrientation.AnyModelDirection;

    // change tag rotation angle to PI/4
    newTag.RotationAngle = Math.PI / 4;

    return newTag;
}
  • The ElementId ownerDBViewId does not correspond to a View. -or- The ElementId ownerDBViewId is a view template. -or- The ElementId ownerDBViewId is a perspective view. -or- The 3D view ownerDBViewId is not locked. -or- The reference can not be tagged.
  • A non-optional argument was null
  • A value passed for an enumeration argument is not a member of that enumeration
  • Tag creation failed.
  • There is no loaded tag type that can be used when tagging referenceToTag with tagMode.
  • The document is in failure mode: an operation has failed, and Revit requires the user to either cancel the operation or fix the problem (usually by deleting certain elements). -or- The document is being loaded, or is in the midst of another sensitive process.
  • The document has no open transaction.