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