Exports a selection of views in DWG format.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Syntax
C# |
---|
|
Visual Basic |
---|
|
Visual C++ |
---|
|
Parameters
- folder
- Type: SystemString
Output folder, into which file(s) will be exported. The folder must exist.
- name
- Type: SystemString
Either the name of a single file or a prefix for a set of files. If empty, automatic naming will be used. If a null reference (Nothing in Visual Basic), throw ArgumentException.
- views
- Type: System.Collections.GenericICollectionElementId
Selection of views to be exported. The set must contain at least one valid view.
- options
- Type: Autodesk.Revit.DBDWGExportOptions
Various options applicable to the DWG format. If a null reference (Nothing in Visual Basic), all options will be set to their respective default values.
Return Value
True if successful, otherwise False.Remarks
All the views must be printable for the Export to succeed. It can be assured by checking the CanBePrinted property of each view.
Examples

public bool ExportDWG(Document document, View view, string setupName)
{
bool exported = false;
// Get the predefined setups and use the one with the given name.
IList<string> setupNames = BaseExportOptions.GetPredefinedSetupNames(document);
foreach (string name in setupNames)
{
if (name.CompareTo(setupName) == 0)
{
// Export using the predefined options
DWGExportOptions dwgOptions = DWGExportOptions.GetPredefinedOptions(document, name);
// Export the active view
ICollection<ElementId> views = new List<ElementId>();
views.Add(view.Id);
// The document has to be saved already, therefore it has a valid PathName.
exported = document.Export(Path.GetDirectoryName(document.PathName),
Path.GetFileNameWithoutExtension(document.PathName), views, dwgOptions);
break;
}
}
return exported;
}

Public Function ExportDWG(document As Document, view As View, setupName As String) As Boolean
Dim exported As Boolean = False
' Get the predefined setups and use the one with the given name.
Dim setupNames As IList(Of String) = BaseExportOptions.GetPredefinedSetupNames(document)
For Each name As String In setupNames
If name.CompareTo(setupName) = 0 Then
' Export using the predefined options
Dim dwgOptions As DWGExportOptions = DWGExportOptions.GetPredefinedOptions(document, name)
' Export the active view
Dim views As ICollection(Of ElementId) = New List(Of ElementId)()
views.Add(view.Id)
' The document has to be saved already, therefore it has a valid PathName.
exported = document.Export(Path.GetDirectoryName(document.PathName), Path.GetFileNameWithoutExtension(document.PathName), views, dwgOptions)
Exit For
End If
Next
Return exported
End Function
Exceptions
Exception | Condition |
---|---|
Autodesk.Revit.ExceptionsArgumentException | NullOrEmpty -or- Contains invalid characters. -or- non empty list of views must be provided. -or- some of the views are not printable (exportable). -or- The modifiers set in layer info must be valid. -or- Thrown when the options in DWGExportOptions is invalid. |
Autodesk.Revit.ExceptionsArgumentNullException | A non-optional argument was null |
Autodesk.Revit.ExceptionsDirectoryNotFoundException | Thrown when the directory does not exist. |
Autodesk.Revit.ExceptionsInvalidOperationException | Export is temporarily disabled. -or- Exporting is not allowed in the current application mode. |
Autodesk.Revit.ExceptionsInvalidPathArgumentException | The folder does not exist. |
Autodesk.Revit.ExceptionsOptionalFunctionalityNotAvailableException | The DWG module is not available in the installed Revit. -or- The Graphics module is not available in the installed Revit. |