While Exporting Views to DWG an Exception System.AccessViolationException accur
Not applicable
03-11-2018
10:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
Following is the code that I'm using to export all the views in a ViewSheetSet to a DWG format.
However, while exporting the views, an unhandled exception of type 'System.AccessViolationException' occurred in UIFrameworkServices.dll. Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The exception occurred while executing the document.Export(..) method.
I'm not sure how to fix it, can anybody help?
Thanks
public static bool ExportDWG(Document document, ViewSheetSet viewSheetSet, string FileNameDWG) { bool exported = false; // Get the predefined setups and use the one with the given name. IList<string> setupNames = BaseExportOptions.GetPredefinedSetupNames(document); DWGExportOptions dwgOptions = new DWGExportOptions(); dwgOptions.MergedViews = true; dwgOptions.SharedCoords = true; // Get all viewsID in a viewsheetset IList<ElementId> viewsIDs = viewSheetSet.Views.Cast<Autodesk.Revit.DB.View>() .Where(view => view.CanBePrinted == true) .Select(view => view.Id) .ToList(); using (Transaction transaction = new Transaction(document, "DWG Export")) { transaction.Start(); try { exported = document.Export(Path.GetDirectoryName(FileNameDWG), Path.GetFileNameWithoutExtension(FileNameDWG), viewsIDs, dwgOptions); } catch (Exception ex) { } transaction.RollBack(); } return exported; }
Link copied