Conversion Examples


Export to StreamCache

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

converter.Init(your_license_key)
importer.Init(&converter)
if (!importer.Load(path_to_your_model_file, importOptions))
{
// handle error
}
exporter->Init(&importer)
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 Communicator::Camera "custom camera" to write a PNG image:

converter.Init(license_key)
importer.Init(&converter)
if (!importer.Load(import_path, importOptions))
{
// handle error
}
//Camera Properties
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
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.

converter.Init(license_key)
importer.Init(&converter)
if (!importer.Load(path_to_your_model_file, importOptions))
{
// handle error
}
exporter->Init(&importer)
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:

converter.Init(your_license_key)
importer.Init(&converter)
if (!importer.Load(path_to_your_model_file, importOptions))
return false
exporter->Init(&importer)
// Set up export options
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 Communicator HTML template that includes basic UI features:

converter.Init(your_license_key)
importOptions.read_attributes = true
importer.Init(&converter)
if (!importer.Load(path_to_your_model_file, importOptions))
{
// handle error
}
exporter->Init(&importer)
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 Communicator package. The minimal template is a self-contained template, whereas the full template includes source links to Communicator's javascript libraries.

These templates are both located in the following location:

  • 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:

converter.Init(license_key)
importer.Init(&converter)
if (!importer.Load(path_to_your_model_file, importOptions))
{
// handle error
}
exporter->Init(&importer)
exporter->WritePDF(output_file_path, pdf_template_file_path, "", Color(0,0,0,1), exportOptions )

A PDF template is available in the Communicator package, located in one of the following locations:

  • authoring/converter/bin/<platform>/HOOPSCommunicatorTemplate.pdf

top_level:2 prog_guide:1 data_import:0 cad_conversion:1