Start
[Transaction (TransactionMode. Manual)]
CreatPipeDiameterTag: IExternalCommand
{
IExternalCommand Members
Result Execute (ExternalCommandData commandData, message, ElementSet elements)
{
UIDocument uiDoc = commandData. Application. ActiveUIDocument;
Document doc = uiDoc. Document; Autodesk. Revit. DB. View view = uiDoc. ActiveView; Selection sel = uiDoc. Selection; Transaction ts = Transaction (doc ,);
{
Ts. Start ();
PipeSelectionFilter psf = PipeSelectionFilter (doc );
Reference refer = sel. PickObject (ObjectType. Element, psf ,);
Pipe pipe = doc. GetElement (refer) Pipe;
(Pipe =)
{
Ts. Dispose ();
TaskDialog. Show (,);
Result. Failed;
}
TagMode tageMode = TagMode. TM_ADDBY_CATEGORY;
TagOrientation tagOri = TagOrientation. Horizontal;
LocationCurve locCurve = pipe. Location LocationCurve;
XYZ pipeMid = locCurve. Curve. Evaluate (,);
IndependentTag tag = doc. Create. NewTag (view, pipe, tageMode, tagOri, pipeMid );
FilteredElementCollector filterColl = GetElementsOfType (doc, (FamilySymbol), BuiltInCategory. OST_PipeTags );
ElId =;
(Element el filterColl. ToElements ())
{
(El. Name =)
ElId = el. Id. IntegerValue;
}
Tag. ChangeTypeId (ElementId (elId ));
ElementId eId =;
(Tag =)
{
Ts. Dispose ();
TaskDialog. Show (,);
Result. Failed;
}
ICollection <ElementId> eSet = tag. GetValidTypes ();
(ElementId item eSet)
{
(Item. IntegerValue =)
{
EId = item;
}
}
Tag = doc. get_Element (eId) IndependentTag;
}
(Exception)
{
Ts. Dispose ();
Result. Cancelled;
}
Ts. Commit ();
Result. Succeeded;
}
FilteredElementCollector GetElementsOfType (Document doc, Type type, BuiltInCategory bic)
{
FilteredElementCollector collector = FilteredElementCollector (doc );
Collector. OfCategory (bic );
Collector. OfClass (type );
Collector;
}
}
PipeSelectionFilter: ISelectionFilter
{
ISelectionFilter Members
Document doc =;
PipeSelectionFilter (Document document)
{
Doc = document;
}
AllowElement (Element elem)
{
Elem Pipe;
}
AllowReference (Reference reference, XYZ position)
{
Doc. GetElement (reference) Pipe;
}
} End