public static void ProjectStartup(AddInId id, Document doc) { using (TransactionGroup tg = new TransactionGroup(doc, "Preupdater Registration")) { tg.Start(); if (!doc.IsFamilyDocument) { using (Transaction t = new Transaction(doc, "Add Parameters")) { t.Start(); doc.AddParam(RoomParams.OccupantLoad); doc.AddParam(RoomParams.OccupantLoadFactor); t.Commit(); } Room r; using (Transaction t = new Transaction(doc, "Add Room")) { t.Start(); r = doc.Create.NewRoom(doc.Phases.get_Item(0)); t.Commit(); } Element room = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).FirstOrDefault(); Parameter p = room.get_Parameter(RoomParams.OccupantLoadFactor.Guid); UpdateOccLoad updater = new UpdateOccLoad(id); UpdaterRegistry.RegisterUpdater(updater, doc, true); ElementCategoryFilter rooms = new ElementCategoryFilter(BuiltInCategory.OST_Rooms); ElementId AreaId = new ElementId(BuiltInParameter.ROOM_AREA); UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), rooms, Element.GetChangeTypeParameter(AreaId)); UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), rooms, Element.GetChangeTypeParameter(p.Id)); using (Transaction t = new Transaction(doc, "Add Room")) { t.Start(); doc.Delete(r.Id); t.Commit(); } } tg.Commit(); } }
public static void ProjectShutdown(AddInId id, Document doc) { UpdateOccLoad updater = new UpdateOccLoad(id); UpdaterRegistry.UnregisterUpdater(updater.GetUpdaterId(), doc); }