FBX SDK Programmer's Guide > Importing and Exporting a Scene >

# Exporting a Scene

The FBX SDK can export a scene into various file formats (see Supported File Formats), including both binary and ASCII FBX file formats. Note that only the binary FBX file format supports embedded media (see I/O Settings).

## Initializing the Exporter

The scene exporting functionality of the FBX SDK is abstracted by the FbxExporter class. The steps required to initialize the exporter object and to export the scene are analogous to the steps detailed in Importing a Scene. A FbxExporter object is created using a reference to the program's FbxManager singleton. The FbxExporter::Initialize() method determines the filename and configuration settings of the exporter. This method requires three parameters:

1. The path and filename of the file to which the scene will be exported.
2. The numeric file format identifier. Typically, this parameter is set to -1 to let the exporter automatically detect the file format according to the provided filename's extension.
3. The FbxIOSettings object containing the export configuration options. See I/O Settings for more information.

    #include <fbxsdk.h>
    #include <fbxfilesdk/fbxio/fbxiosettings.h>

    // ...

    // Create the FBX SDK manager
    FbxManager* lSdkManager = FbxManager::Create();

    // Create an IOSettings object.
    FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT );
    lSdkManager->SetIOSettings(ios);

    // ... Configure the FbxIOSettings object here ...

    // Create an exporter.
    FbxExporter* lExporter = FbxExporter::Create(lSdkManager, "");

    // Declare the path and filename of the file to which the scene will be exported.
    // In this case, the file will be in the same directory as the executable.
    const char* lFilename = "file.fbx";

    // Initialize the exporter.
    bool lExportStatus lExporter->Initialize(lFilename, -1, lSdkManager->GetIOSettings());

If any errors occur in the call to FbxExporter::Initialize(), the method will return false. To retrieve the error, call FbxIO::GetLastErrorString() or FbxIO::GetLastErrorID() (observe that FbxExporter is a subclass of FbxIO). For more information on error handling, see Error Handling.

    if(!lExportStatus) {
        printf("Call to FbxExporter::Initialize() failed.\n");
        printf("Error returned: %s\n\n", lExporter->GetLastErrorString());
        return false;
    }

## Exporting a Scene

The FbxExporter::Export() method exports the specified scene (FbxScene) to the file . For more information on building and manipulating scenes with the FBX SDK, see Nodes and the Scene Graph.

NoteDuring an export operation, the root node of a scene is not exported to the file. Only the children of the root node are exported to the file. As such, it is not recommended to associate anything to the root node that should be saved to a file.

    // Create a new scene so it can be populated by the imported file.
    FbxScene* lScene = FbxScene::Create(lSdkManager,"myScene");

    // ... Import a scene, or build a new one ...

    // Export the scene to the file.
    lExporter->Export(lScene);

Once the scene has been exported, the exporter can safely be destroyed to minimize memory allocation.

    // Destroy the exporter.
    lExporter->Destroy();

## File Version Number

Use the FbxManager::GetFileFormatVersion() method to obtain the exported FBX file version number. For the latest FBX file version number, see Supported File Formats.

    // File format version numbers to be populated.
    int lMajor, lMinor, lRevision;

    // Populate the exported file format version numbers.
    FbxManager::GetFileFormatVersion(lMajor, lMinor, lRevision);

As of FBX SDK 2012.0, the header file fbxfilesdk_version.h defines the preprocessor identifer FBXSDK_VERSION_STRING, which represents the version information as a string.

## Exporting With Embedded Media

To export a scene and have its media embedded within the exported FBX file, the binary (or native) FBX file format identifier must be specified in the call to FbxExporter::Initialize(). The following code snippet illustrates how to perform this task. Recall that the FbxIOSettings object must also be configured to embed the scene's media into the file (see I/O Settings).

    // ... Initialize the required objects and variables ...

    // Set the FbxIOSettings EXP_FBX_EMBEDDED property to true.
    (*(lSdkManager->GetIOSettings())).SetBoolProp(EXP_FBX_EMBEDDED, true);

    // Get the appropriate file format.
    int lFileFormat = lSdkManager->GetIOPluginRegistry()->GetNativeWriterFormat();

    // Initialize the exporter to embed the scene's media into the exported file.
    bool lExportStatus lExporter->Initialize(lFilename, lFileFormat, lSdkManager->GetIOSettings());

    // ... Export the scene ...

#### See Also

- Customizing File Formats with FBX SDK I/O Plug-ins