程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Revit API創建標注NewTag

Revit API創建標注NewTag

編輯:C#入門知識

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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved