<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Run macro on Synchronize with Central in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/run-macro-on-synchronize-with-central/m-p/10990969#M20375</link>
    <description>&lt;P&gt;Hi Forum&lt;/P&gt;&lt;P&gt;I have made a project macro, and would like to run it when Synchronizing.&lt;/P&gt;&lt;P&gt;We have an AddIn, where it works great, but i can't figure out how, to achive the same functionallity in a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've managed to create an event for Saving the Document - but would really like to do some other when synchronizing.&lt;/P&gt;&lt;P&gt;My code below builds fine - but it dosn't run the Sync-event.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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&amp;lt;Autodesk.Revit.DB.Events.DocumentSavedEventArgs&amp;gt;(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&amp;lt;Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs&amp;gt;(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");
			}
		}
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;Niclas&lt;/P&gt;</description>
    <pubDate>Tue, 08 Mar 2022 12:29:32 GMT</pubDate>
    <dc:creator>NiclasSassHald</dc:creator>
    <dc:date>2022-03-08T12:29:32Z</dc:date>
    <item>
      <title>Run macro on Synchronize with Central</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/run-macro-on-synchronize-with-central/m-p/10990969#M20375</link>
      <description>&lt;P&gt;Hi Forum&lt;/P&gt;&lt;P&gt;I have made a project macro, and would like to run it when Synchronizing.&lt;/P&gt;&lt;P&gt;We have an AddIn, where it works great, but i can't figure out how, to achive the same functionallity in a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've managed to create an event for Saving the Document - but would really like to do some other when synchronizing.&lt;/P&gt;&lt;P&gt;My code below builds fine - but it dosn't run the Sync-event.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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&amp;lt;Autodesk.Revit.DB.Events.DocumentSavedEventArgs&amp;gt;(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&amp;lt;Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs&amp;gt;(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");
			}
		}
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;Niclas&lt;/P&gt;</description>
      <pubDate>Tue, 08 Mar 2022 12:29:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/run-macro-on-synchronize-with-central/m-p/10990969#M20375</guid>
      <dc:creator>NiclasSassHald</dc:creator>
      <dc:date>2022-03-08T12:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro on Synchronize with Central</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/run-macro-on-synchronize-with-central/m-p/10992685#M20376</link>
      <description>&lt;P&gt;I don't see the complication here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to set up an event in a macro module that runs a macro in a different module then perhaps explore what is possible with the MacroManager API object. Otherwise below test works fine for pre-synchronization event:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Imports System
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI.Selection
Imports System.Collections.Generic
Imports System.Linq

&amp;lt;Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)&amp;gt; _
&amp;lt;Autodesk.Revit.DB.Macros.AddInId("9C3FB51E-D218-4F59-90DB-93ED44B3DE2E")&amp;gt; _
Partial Public Class ThisDocument

Private Sub Module_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
	TaskDialog.Show("Open","XX")
	
	
    	 AddHandler Me.Application.Application.DocumentSynchronizingWithCentral, AddressOf Test1
    End Sub
	
    Private Sub Module_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
		RemoveHandler Me.Application.Application.DocumentSynchronizingWithCentral, AddressOf Test1
    End Sub
    
    
    Public Sub Test1(s As Object, e As Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs)
    	
    	Dim TD As New TaskDialog("Event")
    	TD.MainContent ="Sync ?"
    	TD.CommonButtons = CType( TaskDialogCommonButtons.Ok + TaskDialogCommonButtons.Cancel, TaskDialogCommonButtons)
    	Dim res As TaskDialogResult = TD.Show
    	
    	If res = TaskDialogResult.Cancel Then
    		e.Cancel
    	End If
    	   	
    	
    End Sub
	
End Class&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 00:25:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/run-macro-on-synchronize-with-central/m-p/10992685#M20376</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2022-03-09T00:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro on Synchronize with Central</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/run-macro-on-synchronize-with-central/m-p/11003345#M20377</link>
      <description>&lt;P&gt;Thanks for your reply.&lt;BR /&gt;I forgot to write that it should preferably be in C# - but your code works!&lt;BR /&gt;I have had some help to read- and translate it, so that my own code has become the following:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;		#region Revit Macros generated code
		private void InternalStartup()
		{
			this.Startup += new System.EventHandler(Module_Startup);
			this.Shutdown += new System.EventHandler(Module_Shutdown);
			this.Application.Application.DocumentSynchronizingWithCentral += SyncingEvent;
			
			
		}
		#endregion



    public void SyncingEvent(object s, Autodesk.Revit.DB.Events.DocumentSynchronizingWithCentralEventArgs e)

    {

            TaskDialog.Show("Test", "Sync");

    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 11:34:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/run-macro-on-synchronize-with-central/m-p/11003345#M20377</guid>
      <dc:creator>NiclasSassHald</dc:creator>
      <dc:date>2022-03-14T11:34:48Z</dc:date>
    </item>
  </channel>
</rss>

