Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I have just write code 1 IExternalApplication “Updater” and then I run it successful. It will run when Revit start up .
I have 1 ask : after I run it, I want to create 1 IExternalCommand for disable “Updater” and 1 IExternalCommand for enable “Updater”.
I try to use method “DisableUpdater” but no successful.
Please help me how to create it.
Qa.
Thank you !
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Windows.Forms; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using System.Windows.Media.Imaging; using View = Autodesk.Revit.DB.View; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.Attributes; using Document = Autodesk.Revit.DB.Document; namespace qa { /// <inheritdoc /> /// <remarks> /// This application's main class. The class must be Public. /// </remarks> public class UpdaterSommaire : IExternalApplication { // Both OnStartup and OnShutdown must be implemented as public method public Result OnStartup(UIControlledApplication application) { ElementId idparaPage = new ElementId(152713); ElementId idparaDate = new ElementId(152809); ElementId idparaDessine = new ElementId(334940); ElementId idparaPageName = new ElementId(335879); ElementId idparaIndice = new ElementId(335881); ElementId idparaVerifier = new ElementId(334942); // Register the ElementUpdater1 ElementUpdater1 updater1 = new ElementUpdater1(application.ActiveAddInId); UpdaterRegistry.RegisterUpdater(updater1); ElementCategoryFilter catFilter = new ElementCategoryFilter(BuiltInCategory.OST_GenericAnnotation); UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeParameter(idparaPage)); UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeParameter(idparaDate)); UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeParameter(idparaDessine)); UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeParameter(idparaPageName)); UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeParameter(idparaIndice)); UpdaterRegistry.AddTrigger(updater1.GetUpdaterId(), catFilter, Element.GetChangeTypeParameter(idparaVerifier)); return Result.Succeeded; } public Result OnShutdown(UIControlledApplication application) { // nothing to clean up in this simple case // Unregister the ElementUpdater1 UpdaterRegistry.UnregisterUpdater(new ElementUpdater1(application.ActiveAddInId).GetUpdaterId()); return Result.Succeeded; } } /// <remarks> /// The "HelloWorld" external command. The class must be Public. /// </remarks> [Transaction(TransactionMode.Manual)] public class DisableUpater : IExternalCommand { public static bool enable; // The main Execute method (inherited from IExternalCommand) must be public public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { //ElementUpdater1 updater1 = new ElementUpdater1(revit.Application.ActiveAddInId); //UpdaterRegistry.DisableUpdater(updater1); //ElementUpdater1.m_updateActive = false; enable = false; return Result.Succeeded; } } [Transaction(TransactionMode.Manual)] public class EnableUpater : IExternalCommand { public static bool enable; // The main Execute method (inherited from IExternalCommand) must be public public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements) { //ElementUpdater1.m_updateActive = true; enable = true; return Result.Succeeded; } } public class ElementUpdater1 : IUpdater { //public static bool m_updateActive = true; private AddInId mAddinId; private UpdaterId mUpdaterId; public ElementUpdater1(AddInId id) { mAddinId = id; mUpdaterId = new UpdaterId(mAddinId, new Guid("B2059D9C-799A-48F1-9666-5AC54643D26E")); } #region IUpdater Members public void Execute(UpdaterData data) { Document doc = data.GetDocument(); View activeView = doc.ActiveView; ICollection<Element> colGene = new FilteredElementCollector(doc, activeView.Id) .OfCategory(BuiltInCategory.OST_GenericAnnotation) .ToElements(); string paramName = "Page"; string paramIndice = "Indice"; string paramDate = "Date"; string paramDessine = "Dessine"; string paramVerifie = "Verifie"; HashSet<FamilyInstance> GenericTilte = new HashSet<FamilyInstance>(); HashSet<FamilyInstance> lingSommaire = new HashSet<FamilyInstance>(); foreach (Element element in colGene) { FamilyInstance familyInstance = element as FamilyInstance; if (familyInstance == null) continue; if (familyInstance.Name.Contains("A3")) GenericTilte.Add(familyInstance); if (familyInstance.Name.Contains("Ligne de Sommaire")) lingSommaire.Add(familyInstance); } foreach (Element ele in GenericTilte) { string StringPage = ele.LookupParameter(paramName).AsString(); string stringindice = ele.LookupParameter(paramIndice).AsString(); string stringdate = ele.LookupParameter(paramDate).AsString(); string stringdessine = ele.LookupParameter(paramDessine).AsString(); string stringverifie = ele.LookupParameter(paramVerifie).AsString(); string stringPagename = ele.LookupParameter("PageName").AsString(); foreach (Element ele2 in lingSommaire) { if (ele2.LookupParameter("PageName").AsString() == stringPagename) { ele2.LookupParameter(paramName).Set(StringPage); ele2.LookupParameter(paramIndice).Set(stringindice); ele2.LookupParameter(paramDate).Set(stringdate); ele2.LookupParameter(paramDessine).Set(stringdessine); ele2.LookupParameter(paramVerifie).Set(stringverifie); } } } } public string GetAdditionalInformation() { return "ElementUpdater1"; } public ChangePriority GetChangePriority() { return ChangePriority.Annotations; } public UpdaterId GetUpdaterId() { return mUpdaterId; } public string GetUpdaterName() { return "ElementUpdater1"; } #endregion } }
Solved! Go to Solution.