Exporting

The MFC Sandbox can export to the HOOPS Visualize native format, HSF (HOOPS Stream File), which is a visualization-only format. Additionally, a few 2D images formats are available as well as 2D and 3D PDF. Exporting an HSF file is as simple as calling HPS::Stream::File::Export with a few parameters. The sandbox will look for a model in its segment tree, and if it finds one, it will export that model tree to the file:

void CProgressDialog::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == CProgressDialog::TIMER_ID)
	{
		try
		{
			float						complete;

			HPS::IOResult status;
			status = _notifier.Status(complete);

			// Update our progress control with the file load percent complete.
			int							progress = static_cast<int>(complete * 100.0f + 0.5f);
			_progress_ctrl.SetPos(progress);

			// Update dialog box title with percentage complete
			CAtlString					str;
			str.Format(_T("Loading ... (%d%%)"), progress);
			SetWindowText(str.GetString());

			// Exit on any status other than InProgress
			if (status != HPS::IOResult::InProgress)
			{
				if (status == HPS::IOResult::Success && !_export)
					PerformInitialUpdate();
				EndDialog(0);
			}
		}
		catch (HPS::IOException const &)
		{
			// notifier not yet created
		}
	}

	CDialogEx::OnTimer(nIDEvent);
}

Notice that in this example, we are using a modal progress dialog to watch the export. It polls the associated HPS::Stream::ExportNotifier for status, and will try to draw the scene once it is no longer in progress.

Other file formats use different exporters and export notifiers, so be sure to use one appropriate for the model you’re working with. For example, to export your scene to a JPEG, use HPS::Image::File::Export with an ExportOptionsKit configured for JPEG.

Exporting to 2D PDF is similar to HSF, except we use HPS::Hardcopy::File::Export:

				try 
				{
					HPS::Hardcopy::File::Export(ansiPath, HPS::Hardcopy::File::Driver::PDF,
								_canvas.GetWindowKey(), HPS::Hardcopy::File::ExportOptionsKit::GetDefault());
				}
				catch (HPS::IOException const & e)
				{
					char what[1024];
					sprintf_s(what, 1024, "HPS::Hardcopy::File::Export threw an exception: %s", e.what());
					MessageBoxA(NULL, what, NULL, 0);
				}

When exporting 3D PDFs, you need to specify where the HOOPS Publish resource dir is located. Normally this is going to be <PUBLISH_INSTALL_DIR>/resource/bin. Note that when exporting in 3D, you must provide a valid HPS::SprocketPath <https://docs.techsoft3d.com/hps/latest/build/api_ref/cpp/class_h_p_s_1_1_sprocket_path.html>`_, which is a special type of HPS::KeyPath which can be employed when you’re using a view hierarchy.

				try 
				{
					HPS::Publish::ExportOptionsKit export_kit;
					CADModel cad_model = GetDocument()->GetCADModel();
					if (cad_model.Type() == HPS::Type::ExchangeCADModel)
						HPS::Publish::File::ExportPDF(cad_model, ansiPath, export_kit);
					else
					{
						HPS::SprocketPath sprocket_path(GetCanvas(), GetCanvas().GetAttachedLayout(), GetCanvas().GetFrontView(), GetCanvas().GetFrontView().GetAttachedModel());
						HPS::Publish::File::ExportPDF(sprocket_path.GetKeyPath(), ansiPath, export_kit);
					}
				}
				catch (HPS::IOException const & e)
				{
					char what[1024];
					sprintf_s(what, 1024, "HPS::Publish::File::Export threw an exception: %s", e.what());
					MessageBoxA(NULL, what, NULL, 0);
				}