Revit二次开发--为管道添加标注

代码如下:

	 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        UIDocument uiDoc = commandData.Application.ActiveUIDocument;
        Document doc = uiDoc.Document;
        Pipe pipe = doc.GetElement(new ElementId(1595857)) as Pipe;
        
        View view = doc.ActiveView;

        TagMode tagMode = TagMode.TM_ADDBY_CATEGORY;
        TagOrientation tagOrientation = TagOrientation.Horizontal;//标记的朝向

        LocationCurve location = pipe.Location as LocationCurve;
        XYZ mid = location.Curve.Evaluate(0.5,true);//取得管道的中心点
        Reference reference = new Reference(pipe);//由已知element取得Reference的方法

        using (Transaction trans = new Transaction(doc))
        {
            trans.Start("Creat  IndependentTag");
            IndependentTag tag = IndependentTag.Create(doc, view.Id, reference, true, tagMode, tagOrientation, mid);
            if (null == tag)
            {
                throw new Exception("Create IndependentTag Failed.");
            }

            tag.LeaderEndCondition = LeaderEndCondition.Free;
            tag.HasLeader = false;//不要箭头
            //XYZ elbowPnt = mid + new XYZ(2.0, 2.0, 0.0);
            //tag.LeaderElbow = elbowPnt;//有箭头的话,箭头拐点
            XYZ headerPnt = mid + new XYZ(2.0, 2.0, 0.0);
            tag.TagHeadPosition = headerPnt;//标记的位置
            trans.Commit();
        }
        return Result.Succeeded;
    }

Revit2018版本,如有问题,请多多指教;

  • 3
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值