Drawings SDK Developer Guide > Getting Started with Drawings SDK > Using Sample Applications >
Exporting a Drawing File to an .svg File

Summary

ODA Product: Drawings SDK
Sample Name: OdSvgExportEx
Categories: C++ / Working with .dwg files / Android, iOS, macOS, Linux, Windows
Location: <INSTALL_DIR>/Drawings/Examples/OdSvgExportEx

Description

OdSvgExportEx is a simple console application used for reading a .dwg or .dxf file and saving it to an .svg file. It illustrates the usage of Kernel/Exports/SvgExport functionality.

Run Sample Application

To run the OdSvgExportEx sample application, please do the following:

  1. Open the terminal and go to the directory where the sample binary file is built:
    • For Windows: <INSTALL_DIR>\exe\<PLATFORM_NAME>\
    • For Non-Windows OS: <INSTALL_DIR>/bin/<PLATFORM_NAME>/
    <INSTALL_DIR> is a directory where you unpacked the Drawings SDK archive.
    To determine your <PLATFORM_NAME> parameter, please see the ODA Platform Naming Conventions section in the Downloading Drawings SDK topic.
  2. Run the sample with appropriate arguments:
    OdSvgExportEx <source file> <target file>
source file A full path to a .dwg or .dxf file to read data from.
target file A full path to an .svg file to write data to.

If the application executed properly, you will see the source file loading progress and a message, informing that the database conversion is finished. In case you get the "usage" message, check the parameters. An error message indicates problems with the source file.

Additional Information

The application reads the specified input .dwg or .dxf file, creates a drawing database, sets export parameters and then exports the database to the specified output (.svg) file.

Export functionality is implemented through an instance of the OdGsDevice class, which renders the content of the drawing database into SVG XML structure.

A full list of .svg export parameters can be found in the Exporting to an SVG File topic of the Developer's Guide.

The source code of the example can be reviewed in the <INSTALL_DIR>/Drawing/Examples/OdSvgExportEx/OdSvgExportEx.cpp file. This file contains:

  • Declaration and definition of the MyServices class, which implements a combination of the platform-dependent functionality (platform-dependent operations and progress metering) for .dwg and .dxf files.
  • Application entry point: the main() function.

The main() function checks input arguments, creates a custom services instance (a MyServices object), initializes the Drawings SDK libraries and then runs the export procedure:

  1. Creates a database by reading a specified file.
  2. Loads OdSvgExportModule, which is needed for SVG format export functionality.
  3. Creates an instance of an OdGsDevice-derived device.
  4. Creates a file steam for writing the output SVG format content.
  5. Sets device properties, which define the export parameters. For additional information about parameters for exporting to an .svg file, see Exporting to an SVG File.
  6. Sets an active palette for the exporting device.
  7. Creates a database context for the exporting device and sets its parameters (database pointer, switching off the rendering of paper background and borders).
  8. Prepares the device for rendering only the active layout in the exported database.
  9. Sets the device coordinate space (by default only the current viewport is exported). See Exporting to an SVG File for additional information about setting the device coordinate space.
  10. Prepares the device for rendering only the active layout in the exported database.
  11. Processes the rendering.

If an error occurs, the application generates an error message and prints it to the console.

See also:

Using the Sample Code
Exporting to an SVG File

Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.