Loading

Loading

Revit二次开发-利用DMU让墙实现不自动连接

- 利用IUpdater接口实现墙的不自动连接,这个功能从Revit2017开始,官方已经添加了。
- https://github.com/iamlovedit/RevitDevSamples.git

直接上代码:

实现 IUpdater接口

public class WallUpdater : IUpdater
    {
        public UpdaterId UpdaterId { get; }
        public ElementFilter ElementFilter { get; } = new ElementClassFilter(typeof(Wall));
        public ChangeType ChangeType { get; } = Element.GetChangeTypeElementAddition();
        public WallUpdater(AddInId addinId)
        {
            UpdaterId = new UpdaterId(addinId, addinId.GetGUID());
        }
        public void Execute(UpdaterData data)
        {
            Document m_doc = data.GetDocument();
            IEnumerable<Wall> m_addedWalls = data.GetAddedElementIds().Select(m_doc.GetElement).OfType<Wall>();
            foreach (var wall in m_addedWalls)
            {
                for (int i = 0; i < 2; i++)
                {
                    if (WallUtils.IsWallJoinAllowedAtEnd(wall, i))
                    {
                        WallUtils.DisallowWallJoinAtEnd(wall, i);
                    }
                }
            }
        }

        public string GetAdditionalInformation()
        {
            return "Disallow Walls Join";
        }

        public ChangePriority GetChangePriority()
        {
            return ChangePriority.InteriorWalls | ChangePriority.FloorsRoofsStructuralWalls;
        }

        public UpdaterId GetUpdaterId()
        {
            return UpdaterId;
        }

        public string GetUpdaterName()
        {
            return "WallUpdater";
        }
    }

IExternalCommand

[Transaction(TransactionMode.Manual)]
    public class MakeWallsDisjoin : IExternalCommand
    {
        private UIDocument m_uidoc;
        private Document m_doc;
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            m_uidoc = commandData.Application.ActiveUIDocument;
            m_doc = m_uidoc.Document;
            WallUpdater m_wallUpdater = new WallUpdater(commandData.Application.ActiveAddInId);
            UpdaterRegistry.RegisterUpdater(m_wallUpdater, m_doc);
            UpdaterRegistry.AddTrigger(m_wallUpdater.UpdaterId, m_wallUpdater.ElementFilter, m_wallUpdater.ChangeType);
            return Result.Succeeded;
        }
    }

 

posted @ 2023-03-20 18:07  热情定无变  阅读(162)  评论(0)    收藏  举报