IUpdater インタフェースには次の 5 つのメソッドを実装する必要があります。
GetUpdaterId() - このメソッドはアップデータのグローバルに一意の ID を返します。この ID はアプリケーション ID とこのアップデータの GUID で構成されます。このメソッドは、アップデータの登録中に一度だけ呼び出されます。
GetUpdaterName() - これは、アップデータの実行時に問題が発生した場合に、ユーザがアップデータを特定するために使用する名前を返します。
GetAdditionalInformation() - このメソッドは、アップデータがロードされない場合に、エンド ユーザに通知するために使用される補助テキストを返します。
GetChangePriority() - このメソッドは、アップデータが実行する変更の種類を特定します。アップデータの実行順序を特定するために使用されます。このメソッドは、アップデータの登録中に一度だけ呼び出されます。
Execute() - これは、Revit が更新を実行するために呼び出すメソッドです。Execute()の詳細については、次のセクションを参照してください。
ドキュメントがアップデータによって変更された場合、そのドキュメントはアップデータの一意の ID を格納します。後でユーザがドキュメントを開いたときにアップデータがない場合は、アップデータに省略可能のフラグが設定されていないと、以前にドキュメントを編集したサード パーティのアップデータが使用できないとの警告が表示されます。既定ではアップデータは省略不可となっており、省略可能なアップデータは必要な場合にのみ使用する必要があります。
次のコードは、IUpdater インタフェースを実装し(新たに追加した壁の WallType を変更するため)、アップデータを OnStartup()メソッドに登録する簡単な例です。これは、アップデータの作成と使用に関する主要な側面をすべて表しています。
コード領域 25-1: IUpdater の実装例 |
public class WallUpdaterApplication : Autodesk.Revit.UI.IExternalApplication { public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application) { // Register wall updater with Revit WallUpdater updater = new WallUpdater(application.ActiveAddInId); UpdaterRegistry.RegisterUpdater(updater); // Change Scope = any Wall element ElementClassFilter wallFilter = new ElementClassFilter(typeof(Wall)); // Change type = element addition UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), wallFilter, Element.GetChangeTypeElementAddition()); return Result.Succeeded; } public Result OnShutdown(Autodesk.Revit.UI.UIControlledApplication application) { WallUpdater updater = new WallUpdater(application.ActiveAddInId); UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId()); return Result.Succeeded; } } public class WallUpdater : IUpdater { static AddInId m_appId; static UpdaterId m_updaterId; WallType m_wallType = null; // constructor takes the AddInId for the add-in associated with this updater public WallUpdater(AddInId id) { m_appId = id; m_updaterId = new UpdaterId(m_appId, new Guid("FBFBF6B2-4C06-42d4-97C1-D1B4EB593EFF")); } public void Execute(UpdaterData data) { Document doc = data.GetDocument(); // Cache the wall type if (m_wallType == null) { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(WallType)); var wallTypes = from element in collector where element.Name == "Exterior - Brick on CMU" select element; if (wallTypes.Count<Element>() > 0) { m_wallType = wallTypes.Cast<WallType>().ElementAt<WallType>(0); } } if (m_wallType != null) { // Change the wall to the cached wall type. foreach (ElementId addedElemId in data.GetAddedElementIds()) { Wall wall = doc.GetElement(addedElemId) as Wall; if (wall != null) { wall.WallType = m_wallType; } } } } public string GetAdditionalInformation() { return "Wall type updater example: updates all newly created walls to a special wall"; } public ChangePriority GetChangePriority() { return ChangePriority.FloorsRoofsStructuralWalls; } public UpdaterId GetUpdaterId() { return m_updaterId; } public string GetUpdaterName() { return "Wall Type Updater"; } } |