- 利用IUpdater接口實作牆的不自動連接配接,這個功能從Revit2017開始,官方已經添加了。
- https://github.com/iamlovedit/RevitDevSamples.git
直接上代碼:
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";
}
}
[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;
}
}