Message 1 of 12
Edit parameter on FileExporting event

Not applicable
11-02-2017
01:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to create a script that ensures that a certain parameter is updated before the file is exported. The problem is that everything inside the transaction is omitted. What can I do to solve this?
This is what I have done so far:
I found AutoUpdate in SDK samples that changes ProjectInformation.Address property on DocumentOpened.
According to revitapidocs.com you are allowed to make changes to the document (I have checked that .IsReadOnly returns false).
Remarks This event is raised when Revit is just about to export files of formats supported by the API. Handlers of this event are permitted to make modifications to any document (including the active document), except for documents that are currently in read-only mode. Event is cancellable. To cancel it, call the 'Cancel()' method in event's argument to True. Your application is responsible for providing feedback to the user about the reason for the cancellation. The following API functions are not available for the current document during this event: All overloads of Autodesk.Revit.DB.Document.Export() Autodesk.Revit.Document.Print() Print and similar overloads. SubmitPrint and similar overloads. Close and similar overloads. Save . SaveAs(String) and similar overloads.
Here is a simple application macro that is supposed to set the comments parameter to a beam to "test". To test it run the ExportEventRegister() macro first, then export the file to trigger the event.
public void ExportEventRegister() { this.Application.FileExporting += new EventHandler<FileExportingEventArgs>(myExportingEvent); } private void myExportingEvent(object sender, FileExportingEventArgs args) { FilteredElementCollector fec = new FilteredElementCollector(args.Document).OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType(); Transaction t1 = new Transaction(args.Document, "test"); t1.Start(); foreach (Element element in fec) { element.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS).Set("test"); } t1.Commit(); }