As previously discussed, methods are available for importing files (see Importing files into layers) and exporting files (see Exporting files from documents).
These file-import and file-export methods can also be used for performing batch conversions or modifying file repositories.
The wide selection of supported file formats is due to the vast number of filters that are available to the application. Each filter lets you work with the files from another graphics application.
To learn more about working with filters, see the following subtopics:
To ensure the portability of a file-import script, you must use the default ImportFilter object (rather than the filter-specific object DSFImport), as in the following VBA example:
Sub OpenRectangle() Dim FilterObject As ImportFilter 'Initialize FilterObject Set FilterObject = ActiveLayer.ImportEx("C:\devo\rect.dsf", cdrDSF) 'Set the advanced features of the filter FilterObject.DefaultLinestyle = 1 'Dashed FilterObject.DeleteInvisibleObjects = True 'Invoke the filter FilterObject.Finish End Sub
For best results, use the filter-specific object DSFImport only to learn the specific interfaces that are supported by a filter. For example, the following screenshot demonstrates that the ImportFilter object exposes only generic interfaces in Microsoft IntelliSense because the ImportFilter interface is generic (and not filter-specific). The ImportFilter object does not contain the DefaultLinestyle and DeleteInvisibleObjects properties; however, you can still set these properties in the ImportFilter interface if they are supported by the specified import filter.
As previously discussed, using the ImportFilter object (rather than the filter-specific object DSFImport) ensures that a file-import script can be used on any other workstation running the same version of the application. To reference the properties, methods, and enumerations for a specific filter, locate that filter in the Object Browser. For example, the following screenshot demonstrates that the line-style dsfDashed2 can be specified by assigning a value of 7 to the DefaultLinestyle property.
To access the object model for a filter, click Tools References from within the Macro Editor. In the References dialog box that appears, click Browse, and navigate to the Filters folder of the installed software. Select the dynamic-link library (DLL) file for the desired filter, and then click OK. When the References dialog box reappears, enable the checkbox that corresponds to the desired filter, and then click OK. You can now access the object model for the filter, as in the following VBA example:
Sub OpenRectangleDSF() Dim FilterObject As DSFImport Dim Style As DsfLinestyle 'Initialize FilterObject Set FilterObject = ActiveLayer.ImportEx("C:\devo\rect.dsf", cdrDSF) 'Set the advanced features of the filter Style = dsfDashed FilterObject.DefaultLinestyle = Style FilterObject.DeleteInvisibleObjects = True 'Invoke the filter FilterObject.Finish End Sub
Working with an import filter is made much easier by having the script access the object model for that filter; however, as discussed, this technique reduces the portability of the script. When used at another workstation, the script must first be updated with the correct location of the DLL file for the filter.
The following VBA example demonstrates how to save a document as an AutoCAD DXF file by using an export filter:
Sub SaveRectangleDXF() Dim FilterObject As DXFExport Dim BitmapType As DxfBitmapType Dim TextAsCurves As Boolean Dim Units As DxfUnits Dim Version As DxfVersion 'Initialize FilterObject Set FilterObject = ActiveDocument.ExportEx("C:\devo\rect.dxf", cdrDXF) 'Set the advanced features of the filter BitmapType = dxfBitmapGIF FilterObject.BitmapType = BitmapType Units = dxfInches FilterObject.Units = Units TextAsCurves = False FilterObject.TextAsCurves = TextAsCurves Version = dxfVersion2000 FilterObject.Version = Version 'Invoke the filter FilterObject.Finish End Sub
In the preceding example, a call is made to ActiveDocument.ExportEx method, and the interface for the export filter (DXFExport) is invoked. However, you can use the generic export interface (ExportFilter) rather than the filter-specific interface (DXFExport), as in the following VBA example:
Sub SaveRectangle() Dim FilterObject As ExportFilter 'Initialize FilterObject Set FilterObject = ActiveDocument.ExportEx("C:\devo\rect.dxf", cdrDXF) 'Set the advanced features of the filter FilterObject.BitmapType = 1 'GIF FilterObject.Units = 0 'Inches FilterObject.TextAsCurves = False FilterObject.Version = 1 'AutoCAD 2000 'Invoke the filter FilterObject.Finish End Sub
The following VBA example demonstrates how to invoke the Export dialog box:
Sub ShowExportDialog() Dim FilterObject As ExportFilter Dim vntReturn As Variant 'Initialize FilterObject Set FilterObject = ActiveDocument.ExportEx("C:\devo\rect.dxf", cdrDXF) 'If FilterObject supports a dialog, invoke it If (FilterObject.HasDialog = True) Then vntReturn = FilterObject.ShowDialog 'Verify that the user clicked "OK" and not "Cancel" If (vntReturn = True) Then 'Invoke the filter FilterObject.Finish End If End If End Sub
The preceding example requires you to check the return value of the dialog box, and to invoke the Finish method for when the user clicks OK.