start

/// <summary>
/// 创建水管管径标注
/// </summary>
[Transaction(TransactionMode.Manual)]
public class CreatPipeDiameterTag : IExternalCommand
{
    #region IExternalCommand Members     public Result Execute(ExternalCommandData commandData, ref string 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 = new Transaction(doc, "水管管径标记");
        try
        {
            ts.Start();
            PipeSelectionFilter psf = new PipeSelectionFilter(doc);
            Reference refer = sel.PickObject(ObjectType.Element, psf, "请选择要标注的水管:");
            Pipe pipe = doc.GetElement(refer) as Pipe;
            if (pipe == null)
            {
                ts.Dispose();
                TaskDialog.Show("RevitMassge", "没有选中水管");
                return Result.Failed;
            }
            //Define tag mode and tag orientation for new tag
            TagMode tageMode = TagMode.TM_ADDBY_CATEGORY;
            TagOrientation tagOri = TagOrientation.Horizontal;
            //Add the tag to the middle of duct
            LocationCurve locCurve = pipe.Location as LocationCurve;
            XYZ pipeMid = locCurve.Curve.Evaluate(0.275, true);
            IndependentTag tag = doc.Create.NewTag(view, pipe, false, tageMode, tagOri, pipeMid);
            //遍历类型
            FilteredElementCollector filterColl = GetElementsOfType(doc, typeof(FamilySymbol), BuiltInCategory.OST_PipeTags);
            //WinFormTools.MsgBox(filterColl.ToElements().Count.ToString());
            int elId = ;
            foreach (Element el in filterColl.ToElements())
            {
                if (el.Name == "管道尺寸标记")
                    elId = el.Id.IntegerValue;
            }
            tag.ChangeTypeId(new ElementId(elId));
            ElementId eId = null;
            if (tag == null)
            {
                ts.Dispose();
                TaskDialog.Show("RevitMassge", "创建标注失败!");
                return Result.Failed;
            }
            ICollection<ElementId> eSet = tag.GetValidTypes();
            foreach (ElementId item in eSet)
            {
                if (item.IntegerValue == )
                {
                    eId = item;
                }
            }
            tag = doc.get_Element(eId) as IndependentTag;
        }
        catch (Exception)
        {
            ts.Dispose();
            return Result.Cancelled;
        }
        ts.Commit();         return Result.Succeeded;
    }
    FilteredElementCollector GetElementsOfType(Document doc, Type type, BuiltInCategory bic)
    {
        FilteredElementCollector collector = new FilteredElementCollector(doc);         collector.OfCategory(bic);
        collector.OfClass(type);         return collector;
    }
    #endregion
} /// <summary>
///水管选择过滤器
/// </summary>
public class PipeSelectionFilter : ISelectionFilter
{
    #region ISelectionFilter Members     Document doc = null;
    public PipeSelectionFilter(Document document)
    {
        doc = document;
    }     public bool AllowElement(Element elem)
    {
        return elem is Pipe;
    }     public bool AllowReference(Reference reference, XYZ position)
    {
        return doc.GetElement(reference) is Pipe;
    }     #endregion
}

end

Revit API创建标注NewTag的更多相关文章

  1. Revit API 创建带箭头的标注

      [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class cmd : ...

  2. Revit api 创建族并加载到当前项目

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. Revit API创建墙的保温层修改墙厚度

    start [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)]  / ;         ; ...

  4. Revit API创建标高,单位转换

    一业内朋友让我写个快速创建标高的插件. ;             ; i <= iNum; i++)             {                 Level level = d ...

  5. Revit API创建一个拷贝房间内对象布局命令

    本课程演示创建一个拷贝房间内对象布局命令,完整演示步骤和代码.这个命令把选中房间内的对象复制到其它选中的一个或多个房间中,而且保持与源房间一致的相对位置.通过本讲座使听众知道创建一个二次开发程序很简单 ...

  6. Revit API创建几何实体Solid并找到与之相交的元素

    几何实体的创建方法之一:构成封闭底面,指定拉伸方向与拉伸高度.GeometryCreationUtilities ;         , pt.Y - dBoxLength / , pt.Z);    ...

  7. Revit api 创建楼梯图元

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. Revit API创建详图视图

    start //创建详图视图 Transaction ts = new Transaction(doc, "http://greatverve.cnblogs.com"); ts. ...

  9. Revit通过API创建共享参数

    Revit共享参数是通过创建一个.txt类型的文件来保存相关信息,一旦与项目保存完毕之后,共享参数也就变成了项目参数(项目参数无法通过API创建),项目参数是保存在Revit项目里面的,所以此时这个. ...

随机推荐

  1. Idea xml 粘贴文本保持原有格式

    setting->Editor->Code Style->XML 在右边的面板中,单击第二个 “Other” 的页签,勾选“Keep white spaces”,重启idea.

  2. 并发研究之Java内存模型(Java Memory Model)

    Java内存模型JMM java内存模型定义 上一遍文章我们讲到了CPU缓存一致性以及内存屏障问题.那么Java作为一个跨平台的语言,它的实现要面对不同的底层硬件系统,设计一个中间层模型来屏蔽底层的硬 ...

  3. 关系操作符 < > = == <= >= !=

    基本类型可以用所有的操作符 对象要用equal eqauls() //用法 System.out.println(v1.equals(v2)); JAVA学习(二) STRING使用EQUALS方法和 ...

  4. Laravel attribute casting 导致的 Indirect modification of overloaded property

    在 Laravel model 中,设置了某个属性做 array casting. protected $casts = [ 'rounds' => 'array', ]; 但是在 contro ...

  5. pytest十一:函数传参和 firture 传参数 request

    为了提高代码的复用性,我们在写用例的时候,会用到函数,然后不同的用例去调用这个函数.比如登录操作,大部分的用例都会先登录,那就需要把登录单独抽出来写个函数,其它用例全部的调用这个登录函数就行.但是登录 ...

  6. python 全栈开发,Day52(关于DOM操作的相关案例,JS中的面向对象,定时器,BOM,client、offset、scroll系列)

    昨日作业讲解: 京东购物车 京东购物车效果: 实现原理: 用2个盒子,就可以完整效果. 先让上面的小盒子向下移动1px,此时就出现了压盖效果.小盒子设置z-index压盖大盒子,将小盒子的下边框去掉, ...

  7. canvas扩散圆环

    最近看了很多牛的动画,想想自己的canvas的确很菜. 公式在那里,但是不是太会套.找demo发现都是很难的 于是找了个简单的效果 圆环从中间扩散的效果 关键是 globalCompositeOper ...

  8. 【AtCoder】AGC019

    A - Ice Tea Store 算一下每种零售最少的钱就行,然后优先买2,零头买1 #include <bits/stdc++.h> #define fi first #define ...

  9. python全栈开发day42-固定定位等

    一.今日内容: 1.绝对定位盒子居中用法 left:50% margin-left:-盒子的一半宽度.       2.固定定位和固定定位的用法 返回顶部 固定导航栏:        3.阿里的字体图 ...

  10. Asp.Net Core 2.0 项目实战(5)Memcached踩坑,基于EnyimMemcachedCore整理MemcachedHelper帮助类。

    Asp.Net Core 2.0 项目实战(1) NCMVC开源下载了 Asp.Net Core 2.0 项目实战(2)NCMVC一个基于Net Core2.0搭建的角色权限管理开发框架 Asp.Ne ...