When a Structural Framing Tag is placed as an instance, by default, it does not have the Leader Arrowhead set. How can we use the Revit API to set the leader arrowhead.
The Leader Arrowhead parameter is, in fact, part of the Structural Framing Tag's Symbol object. And so when we access the Family Symbol of the Structural Framing Tag, we will be able to access the Built-in Parameter called LEADER_ARROWHEAD. This parameter is what needs to be set in order to set the arrow head for the tag. Here is an example showing list of arrowheads available in a structural template for a Structural Column Tag instance.
Now the value that we wish to set for this type parameter can be obtained by filtering for the Arrowheads that are available in the model/template. This can be done by filtering for elements which are of ElementType and which have the built-in parameter called ALL_MODEL_FAMILY_NAME set to the value 'Arrowhead'. Once we have access to the Arrowhead element that we wish to use, you can set the ID of the Arrowhead element to the LEADER_ARROWHEAD built-in parameter. The following code snippet illustrates this approach for the Structural Column Tag instance shown in the screenshot above.
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.HelloRevit.CS
{
[Transaction(TransactionMode.Manual)]
public class Command : IExternalCommand
{
public Result Execute(ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;
// Access all elements in the model which represent Arrowheads
// This is being done by filtering all elements which
// are of ElementType and have the ALL_MODEL_FAMILY_NAME
// builtIn Parameter set to 'Arrowhead'
ElementId id = new ElementId(
BuiltInParameter.ALL_MODEL_FAMILY_NAME);
ParameterValueProvider provider =
new ParameterValueProvider(id);
FilterStringRuleEvaluator evaluator =
new FilterStringEquals();
FilterRule rule =
new FilterStringRule(provider, evaluator, "Arrowhead", false);
ElementParameterFilter filter =
new ElementParameterFilter(rule);
FilteredElementCollector collector =
new FilteredElementCollector(doc)
.OfClass(typeof(ElementType))
.WherePasses(filter);
using (Transaction trans = new Transaction(doc, "Arrowhead"))
{
trans.Start();
// For simplicity, assuming that the
// Structural Component Tag is selected
foreach (Element selectedElement in
uiApp.ActiveUIDocument.Selection.Elements)
{
IndependentTag tag = selectedElement as IndependentTag;
if (null != tag)
{
// Access the Symbol of the IndependentTag element
FamilySymbol tagSymbol =
doc.GetElement(tag.GetTypeId()) as FamilySymbol;
// Set the LEADER_ARROWHEAD parameter of the
// Symbol with one of the arrowheads that was filtered
tagSymbol.get_Parameter(BuiltInParameter.LEADER_ARROWHEAD)
.Set(collector.ToElementIds()
.ElementAt<ElementId>(0));
}
trans.Commit();
}
}
return Result.Succeeded;
}
}
}
After executing this code, in which for simplicity sake, we are just setting the first extracted arrowhead to the tag – we can see that the leader had a arrowhead set to it.