请选择 进入手机版 | 继续访问电脑版
用户登录
找回密码
立即注册
搜索
热搜: 视频教程
查看: 4557|回复: 0

标注归一

[复制链接]

9

主题

21

帖子

101

积分

注册会员

Rank: 2

积分
101
发表于 2022-5-19 18:54:01 | 显示全部楼层 |阅读模式
本帖最后由 GLS测试组_LY 于 2022-5-26 09:52 编辑

在低版本的revit中,如果标注的内容一样的话是不能用一个标注来标注多个element的;想到一个折中的方法就是把相同标注内容的标注放到同一个位置来实现效果,如下图: 企业微信截图_20220519185022.png


分享一段小代码,revit2018亲测有效。

namespace 标注归一
{
    //开发需求:把相同的注释放到同一个位置
    [Transaction(TransactionMode.Manual)]

    class OneLeadDIM : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.UI.UIApplication uiApp = commandData.Application;
            Autodesk.Revit.ApplicationServices.Application app = uiApp.Application;
            Autodesk.Revit.UI.UIDocument uidoc = uiApp.ActiveUIDocument;
            Autodesk.Revit.DB.Document doc = uidoc.Document;



            Transaction ts = new Transaction(doc, "标注归一");

            try
            {
                Selection sel = uidoc.Selection;
                Reference refe1 = sel.PickObject(ObjectType.Element,new IndependentTagFilter(),"选择基准标注");
                Element ele1 = doc.GetElement(refe1) as Element;
                XYZ point = null;
                TagOrientation tagOrientation =new TagOrientation();

                string tagtext = null;
                IndependentTag independentTag = ele1 as IndependentTag;
                ts.Start();
                if (independentTag != null)
                {
                    point = independentTag.TagHeadPosition;
                    tagtext = independentTag.TagText;
                    tagOrientation=independentTag.TagOrientation;
                }

                IList<Reference> refs = sel.PickObjects(ObjectType.Element,new IndependentTagFilter(), "选择要合并的标注");
                foreach (var reference in refs)
                {
                    Element ele2 = doc.GetElement(reference) as Element;
                    IndependentTag independentTag2 = ele2 as IndependentTag;
                    if (independentTag2 != null&&independentTag2.TagText== tagtext)
                    {
                        independentTag2.TagHeadPosition = point;
                        independentTag2.TagOrientation = tagOrientation;
                    }
                }
                ts.Commit();
                return Result.Succeeded;

            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)//防止按ESC报错
            {
                ts.RollBack();
                return Result.Cancelled;
            }
            catch (Exception eee)
            {

                message = eee.Message;
                ts.RollBack();
                return Autodesk.Revit.UI.Result.Failed;
            }


        }



    }
    public class IndependentTagFilter : ISelectionFilter
    {
        public bool AllowElement(Element elem)
        {
            if (elem is IndependentTag)
            {
                return true;
            }
            return false;
        }

        public bool AllowReference(Reference reference, XYZ position)
        {
            return true;
        }
    }
}



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Powered by Discuz! X3.4 © 2001-2013 Comsenz Inc.

京ICP备17008402号-1  |  Archiver  |  手机版  |  小黑屋  |  橄榄山BIM论坛    

点击立刻咨询
快速回复 返回顶部 返回列表