Revit API creates a NewTag

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.