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. 【python】中文提取,判断,分词

    参考: http://www.cnblogs.com/kaituorensheng/p/3595879.html https://github.com/fxsjy/jieba 判断是否包含中文 def ...

  2. 【python】正则表达式中的转义问题

    encode('string-escape') 解决 比如想匹配'\x0e\x0a'中的'\x'后的内容,这里希望把'\x0e'作为一个字符串,那么其中的\应该被转义. 未加转义的正则: p = '( ...

  3. python 全栈开发,Day129(玩具开机提示语,为多个玩具发送点播,聊天界面,app录音,app与服务器端文件传输,简单的对话)

    一.玩具开机提示语 先下载github代码,下面的操作,都是基于这个版本来的! https://github.com/987334176/Intelligent_toy/archive/v1.2.zi ...

  4. python 全栈开发,Day86(上传文件,上传头像,CBV,python读写Excel,虚拟环境virtualenv)

    一.上传文件 上传一个图片 使用input type="file",来上传一个文件.注意:form表单必须添加属性enctype="multipart/form-data ...

  5. DDD领域模型数据访问权限之用户权限(十)

    BAS_PRService岗位和角色服务: public class BAS_PRService { //岗位 private IRepository<BAS_Post> ireposit ...

  6. PostgreSQL 列出所有表名和数据库名, 删除session被占用的数据库

    https://blog.csdn.net/Michael_Lbs/article/details/57509940

  7. springbank 开发日志 一次因为多线程问题导致的applicationContext.getBean()阻塞

    几天前遇到的这个问题.由于交易是配置的,不同的交易是同一个类的不同实例,所以不可能提前将其以@autowired类似的方式注入到需要的类中 <op:transaction id="Re ...

  8. 结构型模式之Adapter模式

    适配器模式把一个类的接口变换成客户端所期待的另一种接口. 在JDK中的体现 把一个接口或类变成另外一种. java.util.Arrays#asList()javax.swing.JTable(Tab ...

  9. Linux && 与 ||

    一.&& && 表示前一条命令执行成功时,才执行后一条命令 ,如 echo '1‘ && echo '2' || 表示上一条命令执行失败后,才执行下一条 ...

  10. 【LeetCode】158. Read N Characters Given Read4 II - Call multiple times

    Difficulty: Hard  More:[目录]LeetCode Java实现 Description Similar to Question [Read N Characters Given ...