# Conversion Examples

## Export to StreamCache

The following example exports an imported CAD file to the StreamCache format for viewing in HOOPS Web Viewer:

    Communicator::Converter converter;
    converter.Init(your_license_key);
    Communicator::Importer importer;
    Communicator::SC_Import_Options importOptions;
    importer.Init(&converter);
    if (!importer.Load(path_to_your_model_file, importOptions))
    {
            // handle error
    }

    Communicator::Exporter *exporter = new Communicator::Exporter();
    exporter->Init(&importer);
    Communicator::SC_Export_Options exportOptions;
    exporter->WriteSC(path_to_your_sc_folder, nullptr, exportOptions);

To generate a single, self-contained SCS file, change the second argument to the filepath for the location of your SCS file:

    exporter->WriteSC(nullptr, "C:\\my_path\\my_file.scs", exportOptions);

## Export to PNG with custom camera

The following example uses a custom Communicator::Camera to write a PNG image:

    Communicator::Converter converter;
    converter.Init(license_key);
    Communicator::Importer importer;
    Communicator::SC_Import_Options importOptions;
    importer.Init(&converter);
    if (!importer.Load(import_path, importOptions))
    {
            // handle error
    }
    //Camera Properties
    Communicator::Camera cam;
    cam.projection = Communicator::Camera::Projection::Perspective;
    cam.field_height = 200.0; //Camera View Height
    cam.field_width = 355.0; //Camera View Width
    cam.position[0] = 0; cam.position[1] = 0; cam.position[2] = 1000; //0 is x, 1 is y, 2 is z
    cam.up_vector[0] = 0; cam.up_vector[1] = 1; cam.up_vector[2] = 0; //0 is x, 1 is y, 2 is z
    cam.target[0] = 35; cam.target[1] = 75; cam.target[2] = 0;        //0 is x, 1 is y, 2 is z
    Communicator::Exporter *exporter = new Communicator::Exporter();
    exporter->Init(&importer);
    exporter->WritePNG(export_path, 1920, 1080, Communicator::Color(0.0, 0.0, 0.0, 1.0), &cam, Communicator::ViewOrientation::Unspecified, false, false, false);

## Export to PNG with pre-defined view

The following example uses predefined views to write a PNG image. These views are defined in the Communicator::ViewOrientation enum.

    Communicator::Converter converter;
    converter.Init(license_key);
    Communicator::Importer importer;
    Communicator::SC_Import_Options importOptions;
    importer.Init(&converter);
    if (!importer.Load(path_to_your_model_file, importOptions))
    {
            // handle error
    }
    Communicator::Exporter *exporter = new Communicator::Exporter();
    exporter->Init(&importer);
    Communicator::SC_Export_Options exportOptions;
    exporter->WritePNG(output_file_path, 1920, 1080, Communicator::Color(0.0, 0.0, 0.0, 1.0), nullptr, Communicator::ViewOrientation::TopLeftFront, false, false, false);

## Export to shattered parts

The following example exports a model to shattered parts:

    Communicator::Converter converter;
    converter.Init(your_license_key);
    Communicator::Importer importer;
    Communicator::SC_Import_Options importOptions;
    importer.Init(&converter);
    if (!importer.Load(path_to_your_model_file, importOptions))
            return false;
    Communicator::Exporter *exporter = new Communicator::Exporter();
    exporter->Init(&importer);
    // Set up export options
    Communicator::SC_Export_Options exportOptions;
    exportOptions.prepare_shattered_parts = path_to_parts_dir; // creates a subdirectory here using the part name
    exportOptions.prepare_shattered_xml = path_to_xml_file; // writes assembly data to specified xml file
    exporter->WriteSCShattered(exportOptions);
    Communicator::SC_Export_Options exportOptionsMasterBuild;
    exporter->WriteSCMaster(path_to_xml_file, path_to_parts_dir, path_to_your_sc_output_directory, exportOptionsMasterBuild); // Writes to locations specified above

When Communicator::SC_Export_Options::prepare_shattered_xml is set to `true` in the export options, calling Communicator::Exporter::WriteSCShattered() will write an XML file containing the full assembly structure referencing the external models. Each of these parts will be exported to its own distinct StreamCache model directory.

After the shattered parts are exported, calling Communicator::Exporter::WriteSCMaster() will generate a master StreamCache directory (or SCS file) that references the parts directory created earlier by Communicator::Exporter::WriteSCShattered(). When the master StreamCache instance is loaded in the WebViewer, the individual parts will be available in the model tree.

## Export to HTML with a template

The following example exports a file to HTML, using the customizable HOOPS Visualize Web HTML template that includes basic UI features:

    Communicator::Converter converter;
    converter.Init(your_license_key);
    Communicator::Importer importer;
    Communicator::SC_Import_Options importOptions;
    importOptions.read_attributes = true;
    importer.Init(&converter);
    if (!importer.Load(path_to_your_model_file, importOptions))
    {
            // handle error
    }
    Communicator::Exporter *exporter = new Communicator::Exporter();
    exporter->Init(&importer);
    Communicator::SC_Export_Options exportOptions;
    exporter->WriteHTML(output_file_path, html_template_file_path, exportOptions );

In addition to the full HTML template, a minimal template is also provided in the HOOPS Visualize Web package. The minimal template is a self-contained template, whereas the full template includes source links to HOOPS Visualize Web’s javascript libraries.

These templates can be found at authoring/converter/bin/<platform>/HOOPSCommunicatorTemplate.html

More information about HTML export can be found in the Monolithic HTML Export Programming Guide.

## Export to PDF with a template

NOTE:: PDF export requires a HOOPS Publish license.

The following example exports a model to a PDF file with a black background using a PDF template:

    Communicator::Converter converter;
    converter.Init(license_key);
    Communicator::Importer importer;
    Communicator::SC_Import_Options importOptions;
    importer.Init(&converter);
    if (!importer.Load(path_to_your_model_file, importOptions))
    {
            // handle error
    }
    Communicator::Exporter *exporter = new Communicator::Exporter();
    exporter->Init(&importer);
    Communicator::SC_Export_Options exportOptions;
    exporter->WritePDF(output_file_path, pdf_template_file_path, "", Color(0,0,0,1), exportOptions );

A PDF template is available in the HOOPS Visualize Web package, located at authoring/converter/bin/<platform>/HOOPSVisualizeWebTemplate.pdf

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your Docs generative AI assistant. Ask me anything about HOOPS Visualize Web or choose a sample question below to start a conversation:

What is HOOPS Visualize Web?
What are the latest release notes for HOOPS Visualize Web?
How do I start evaluating HOOPS Visualize Web?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...