Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Forum
I have made a project macro, and would like to run it when Synchronizing.
We have an AddIn, where it works great, but i can't figure out how, to achive the same functionallity in a macro.
I've managed to create an event for Saving the Document - but would really like to do some other when synchronizing.
My code below builds fine - but it dosn't run the Sync-event.
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace RoomNdArea
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("0158DC3D-D3E0-41DB-A020-338B0F039E6F")]
public partial class ThisDocument
{
private void Module_Startup(object sender, EventArgs e)
{
ReferenceLevel();
OnStartup();
}
private void Module_Shutdown(object sender, EventArgs e)
{
this.Document.DocumentSaved -= SavedDocument;
OnShutdown();
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
this.Document.DocumentSaved += new EventHandler<Autodesk.Revit.DB.Events.DocumentSavedEventArgs>(SavedDocument);
}
#endregion
public void ReferenceLevel()
{
Document doc = this.Application.ActiveUIDocument.Document;
FilteredElementCollector rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms);
int r = rooms.ToElements().Count;
Transaction t = new Transaction(doc, "ReferenceLevel");
t.Start();
foreach (Element room in rooms.ToElements()) {
string sVal = room.get_Parameter(BuiltInParameter.LEVEL_NAME).AsString();
string newVal = sVal.Remove(0,sVal.Length - 2);
Parameter p = room.LookupParameter("ZoneName");
p.Set(newVal);
}
t.Commit();
TaskDialog.Show("TEST",r + " Rooms in this model");
}
private void SavedDocument(object sender, EventArgs e){
TaskDialog.Show("TEST","SAVED");
}
public class Sync : IExternalApplication{
public Result OnStartup(Autodesk.Revit.UI.UIControlledApplication application)
{
application.ControlledApplication.DocumentSynchronizingWithCentral += new EventHandler<Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs>(application_ControlledApplication_DocumentSynchronizingWithCentral);
return Result.Succeeded;
}
public Result OnShutdown(Autodesk.Revit.UI.UIControlledApplication application)
{
application.ControlledApplication.DocumentSynchronizingWithCentral -= application_ControlledApplication_DocumentSynchronizingWithCentral;
return Result.Succeeded;
}
public void application_ControlledApplication_DocumentSynchronizingWithCentral(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs args){
TaskDialog.Show("SYNC","SyncToCentral");
}
}
}
}
Best regards
Niclas
Solved! Go to Solution.