While Exporting Views to DWG an Exception System.AccessViolationException accur

Anonymous

While Exporting Views to DWG an Exception System.AccessViolationException accur

Anonymous
Not applicable

 

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; }

 

0 Likes
Reply
663 Views
2 Replies
Replies (2)

Anonymous
Not applicable

I made some progress by creating a new transaction for reach view export to .dwg. It exported few DWG but again the same exception of type 'System.AccessViolationException' occurred. I guess the problem is with the transaction. Appreciate any resolution to this problem. Thank you

 

 

            int i = 0;
            foreach (var viewID in viewsIDs)
            {
                i++;

                using (Transaction transaction = new Transaction(document, "DWG Export" + i))
                {
                    transaction.Start();

                    try
                    {

                        exported = document.Export(Path.GetDirectoryName(FileNameDWG),
                                       Path.GetFileNameWithoutExtension(FileNameDWG) + i + ".dwg", new List<ElementId>() { viewID }, dwgOptions);
                    }
                    catch (Exception ex)
                    {

                    }
                    transaction.RollBack();
                }

            }

 

0 Likes

Anonymous
Not applicable

Hello everyone, I'm still facing this issue, would appreciate any suggestion to solve this issue. Thank you.

0 Likes