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 Communicator 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 Communicator package. The minimal template is a self-contained template, whereas the full template includes source links to Communicator’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 Communicator package, located at authoring/converter/bin/<platform>/HOOPSCommunicatorTemplate.pdf