- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am working on a revit document macro that will help us get the username and central path when the document is exported or printed.
I need the 2 functions to trigger when a file is exported to DWF, printed or exported to DWG. (here i think revit views exporting anything as a single thing so maybe i nee only a single event for them).
I have tried adapting the initial solution i found online that worked for the first function to also trigger the second function. But now after i added the extra line refering the second function nothing happens.
Also i am not clear from what i have read and watched if the order of the written instruction affects when they are executed. I this case my first function is the one that reads the revit data and the second one will move the data to a sheet parameter that is read on the title-block.
Here is the simplified code:
namespace TESTMACRO7
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("EE6F0CDF-D1DC-4A32-A8F4-6959A1CA3B8E")]
public partial class ThisDocument
{
private void Module_Startup(object sender, EventArgs e)
{
this.Application.Application.FileExporting += new EventHandler<Autodesk.Revit.DB.Events.FileExportingEventArgs>(CENTRALPATH_TO_CentralSTRG);
this.Application.Application.FileExporting += new EventHandler<Autodesk.Revit.DB.Events.FileExportingEventArgs>(USERNAMETOX);
}
private void Module_Shutdown(object sender, EventArgs e)
{
this.Application.Application.FileExporting -= new EventHandler<Autodesk.Revit.DB.Events.FileExportingEventArgs>(CENTRALPATH_TO_CentralSTRG);
this.Application.Application.FileExporting -= new EventHandler<Autodesk.Revit.DB.Events.FileExportingEventArgs>(USERNAMETOX);
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
//*--------------- Function 1 omitted to make this easier to read -------------*
internal void CENTRALPATH_TO_CentralSTRG(object sender, FileExportingEventArgs args)
//*------------------End Function 1--------------*
//*-------------- Start Function 2 -------------*
public void USERNAMETOX (object sender, FileExportingEventArgs args)
{
UIDocument uidoc = this;
View view = uidoc.ActiveView;
//collect and set parameter.
FilteredElementCollector collector = new FilteredElementCollector(uidoc.Document)
.OfClass(typeof(ViewSheet))
.WhereElementIsNotElementType();
foreach(Element e in collector)
{
foreach (Parameter p in e.Parameters)
{
if(p.Definition.Name=="CentralLocation")
{
//Start transaction
using (Transaction t = new Transaction(uidoc.Document,"Place family Instance"))
{
t.Start();
//SetParameter
p.SetValueString("GlobalParameter").ToString();
t.Commit();
}
}
}
}
}
}
}
Solved! Go to Solution.