#############
Example Codes
#############

.. toctree::
   :hidden:

   examples/build
   ImportExport <examples/import_export>

This section provides sample applications that demonstrate key features and workflows of the HOOPS Exchange API.  
Each example highlights specific use cases, such as file conversion, metadata extraction, and geometry processing, serving as practical starting points for integrating the API into your projects.  

While we aim to provide examples in both C and C#, some samples are currently available in only one language.  
Future updates will expand language coverage to include all key functionalities.  

In the meantime, you can adapt existing examples to your preferred language, as the C# API mirrors the functionality of the C API through its bindings.  
Refer to the :doc:`/api/cs` for guidance.  

.. csv-table::
   :class: samples-summary
   :header-rows: 1
   :stub-columns: 1

   Name,Description,C/C++,C#,Category
   :ref:`sample_animworkinstruction`,Create animated work instructions,|c_green|,|c_grey|,Publishing
   :ref:`sample_brep_adaptor`,Adapt B-rep models to your needs,|c_green|,|c_green|,Advanced Functions
   :ref:`sample_callbacks_report`,Log CAD file events and errors,|c_grey|,|c_green|,Hello World
   :ref:`sample_cascaded_attributes`,Manage cascaded attributes easily,|c_green|,|c_grey|,PRC Model
   :ref:`sample_collision_detection`,Find collisions in CAD models,|c_green|,|c_grey|,Advanced Functions
   :ref:`sample_count_part_instances`,Count parts in a structure,|c_grey|,|c_green|,Hello World
   :ref:`sample_create_prc_brep`,Generate PRC with geometry,|c_green|,|c_grey|,PRC Model
   :ref:`sample_create_prc_cubes`,Create textured cubes in PRC,|c_green|,|c_green|,PRC Model
   :ref:`sample_demodatamodel`,Create interactive PDF without writing JavaScript,|c_green|,|c_grey|,Publishing
   :ref:`sample_demofunctionalities`,Demonstrate PDF page and table creation,|c_green|,|c_grey|,Publishing
   :ref:`sample_demofunctionalitiesadv`,Demonstrate advanced PDF functionalities,|c_green|,|c_grey|,Publishing
   :ref:`sample_demolayers`,Generate PDFs with layers,|c_green|,|c_grey|,Publishing
   :ref:`sample_dft`,Export features to XML,|c_green|,|c_green|,PRC Model
   :ref:`sample_export3dtohtml`,Export 3D models to HTML,|c_green|,|c_grey|,Publishing
   :ref:`sample_exportpdftohtml`,Export 3D PDFs to HTML,|c_green|,|c_grey|,Publishing
   :doc:`Import Export <examples/import_export>`,Convert a CAD file from one format to another,|c_green|,|c_green|,Hello World
   :ref:`sample_import_publish`,Create a simple 3D PDF with Advanced Publishing,|c_green|,|c_grey|,Hello World
   :ref:`sample_incremental`,Load CAD files step by step,|c_green|,|c_green|,Reading Modes
   :ref:`sample_manufacturing_mbe`,Create a technical data package,|c_green|,|c_grey|,Publishing
   :ref:`sample_mesh_viewer`,Visualize mesh data,|c_green|,|c_grey|,Viewers
   :ref:`sample_multi_prc`,Handle multiple PRC files from a CAD assembly,|c_green|,|c_grey|,Reading Modes
   :ref:`sample_multiconfig`,Handle multi-config CAD files,|c_green|,|c_grey|,Reading Modes
   :ref:`sample_pdfwithbomandcarousel`,Create a scrolling table with 3D assemblies,|c_green|,|c_grey|,Publishing
   :ref:`sample_prc_to_ifc_xml`,Convert PRC to IFC XML format,|c_green|,|c_grey|,PRC Model
   :ref:`sample_prc_to_xml`,Convert PRC to XML format,|c_green|,|c_grey|,PRC Model
   :ref:`sample_print_assy_struct`,View assembly hierarchy,|c_green|,|c_green|,PRC Model
   :ref:`sample_publish_prc_cubes`,Create textured cubes in PRC,|c_green|,|c_grey|,Publishing
   :ref:`sample_sew_b_rep`,Modify and sew B-reps,|c_green|,|c_grey|,Advanced Functions
   :ref:`sample_shattered`,Break assemblies into components,|c_green|,|c_grey|,Reading Modes
   :ref:`sample_translatetopkparts`,Convert CAD to Parasolid,|c_green|,|c_grey|,Bridges
   :ref:`sample_u3dwithanimation`,Add animation to U3D with PDF,|c_green|,|c_grey|,Publishing
   :ref:`sample_updatedata`,Update PDF data,|c_green|,|c_grey|,Publishing
   :ref:`sample_userdefinedviews`,Define and activate custom view,|c_green|,|c_grey|,Publishing

How to Build And Test Our Example Codes
=======================================

Beforehand, make sure you have correctly prepared your environment for building and testing HOOPS Exchange.
Follow the instruction in :doc:`/tutorials/c/environment-setup` for more information.

See :doc:`/examples/build` for more information about building and testing our sample codes.

.. _sample_brep_adaptor:

B-Rep Adaptor
-------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/advanced_functions/BrepAdaptor
   C#,|he_cs_samples_dir|/advanced_functions/BRepAdaptor

B-Rep Adaptor shows how to make use of :cpp:func:`A3DAdaptAndReplaceAllBrepInModelFileAdvanced` to adapt B-rep models to your particular needs.

.. _sample_callbacks_report:

Callbacks Report
----------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C#,|he_cs_samples_dir|/hello_world/CallbacksReport

This application initializes HOOPS Exchange, then load a CAD file. It writes the Exchange log to a file (or standard console output if not specified).
It also implements the message, warning and error callbacks.

.. _sample_cascaded_attributes:

Cascaded Attributes
-------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/prc_model/CascadedAttributes

This sample demonstrates how to programmatically set the mechanism of the cascaded attributes using HOOPS Exchange.

.. _sample_collision_detection:

Collision Detection
-------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/advanced_functions/Collision

This sample illustrates the collision detection feature in HOOPS Exchange.
The sample reads an input CAD file and outputs collision status between representation items.
The user may select which items are tested using their UUIDs; the output is available as a report file.

.. _sample_count_part_instances:

Count Part Instances
--------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C#,|he_cs_samples_dir|/prc_model/CountPartInstances

This application initializes HOOPS Exchange, then walks the product structure to find all part instances.
It writes the part instance count to a log file (or standard console output if not specified).  

.. _sample_create_prc_brep:

Create PRC B-Rep
----------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/prc_model/CreatePRCBrepWithGeometry

This sample demonstrates how to programmatically create a PRC file using HOOPS Exchange.
The only input is the file path.
The program generates a PRC file which contains a warped circle with a thick edge.

.. _sample_create_prc_cubes:

Create PRC Cubes
----------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/prc_model/CreatePRCCubes
   C#,|he_cs_samples_dir|/prc_model/CreatePRCCubes


This sample demonstrates how to create a PRC file with the Exchange API.
The only input is the output file path.
The program generates a PRC file containing a tessellated textured cube that is instantiated multiple times.
The generated output also contains PMIs and Views, as well as links between markups, Views, and entities.

.. _sample_dft:

Dump Feature Tree
-----------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/prc_model/DumpFeatureTree
   C#,|he_cs_samples_dir|/prc_model/DumpFeatureTree

This sample demonstrates how to traverse a model and capture its features in an XML file.

.. _sample_incremental:

Incremental Load
----------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/reading_modes/IncrementalLoad
   C#,|he_cs_samples_dir|/reading_modes/IncrementalLoad

This sample demonstrates two ways of loading a CAD file: normal loading and incremental loading (first the assembly tree, then the parts contained in the file).
Using the incremental loading technique allows a more fine-grained approach, which is especially beneficial when dealing with huge files (e.g., for loading only specific items at a time rather than the whole file in one shot).
The only input is the file path.

.. _sample_mesh_viewer:

Mesh Viewer
-----------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,`GitHub <https://github.com/techsoft3d/he_basic_viewer>`__,:doc:`/tutorials/c/mesh-viewer-sample`
   C/C++,|he_c_samples_dir|/viewers/Viewer

The Mesh Viewer example, added in HOOPS Exchange 2023 SP2 U1, demonstrates how to use the new usability API to access mesh data in representation models.

The :doc:`/tutorials/c/mesh-viewer-sample` tutorial provides more information about it.

.. _sample_multi_prc:

Multiple PRC Files
------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/reading_modes/MultiplePRCFiles

This sample demonstrates how to programmatically create and read multiple PRC files from a CAD assembly using HOOPS Exchange.
The input is the CAD assembly file path and a directory.
The program generates multiple PRC files from this CAD assembly.

This mode is supported for the following formats: V4, V5, ProE, UG, SLDW.
With other formats, only one PRC file is generated.

.. _sample_multiconfig:

Multiple Configurations
-----------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/reading_modes/LoadMultiConfigCADFile

This sample demonstrates how to programmatically load CAD files that contain multiple configurations using HOOPS Exchange.
The only input is the file path.

.. _sample_prc_to_xml:

PRC to XML
----------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/prc_model/PRC2XML

.. _sample_prc_to_ifc_xml:

PRC to IFC XML
--------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/prc_model/PRC2IFCXML

Converts a PRC file to an IFC XML representation.

.. _sample_print_assy_struct:

Print Assembly Structure
------------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,:download:`PrintAssemblyStructure.cpp </_assets/PrintAssemblyStructure.cpp>`,:doc:`Tutorial </tutorials/c/print-assembly-structure>`
   C#,|he_cs_samples_dir|/prc_model/PrintProductStructure

.. _sample_publish_prc_cubes:

Publish PRC Cubes
-----------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++ using Advanced Publishing,|he_c_samples_dir|/publishing/PublishPRCCubes

The advanced publishing version of the sample is similar to :ref:`the standard one <sample_create_prc_cubes>`, but also writes the result in PDF views.

.. _sample_sew_b_rep:

Sew B-Rep
---------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/advanced_functions/SewBrep

This sample demonstrates how to programmatically adapt B-rep models to particular needs using HOOPS Exchange.

The only input is the CAD file path.

* Load a CAD file
* Traverse the entire data structure
* Call A3DSewBrep for each B-rep model
* New modified data are populated
* PRC is exported from the modified data

.. _sample_shattered:

Shattered
---------

.. csv-table::
   :class: samples
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/reading_modes/Shattered

This sample demonstrates how to use the shattered mode in HOOPS Exchange.
The input is the CAD assembly file path and a directory.
The program generates multiple PRC files from this CAD assembly.

* Load a CAD assembly
* Extract all dependencies from the CAD assembly
* Convert CAD part files to PRC
* Convert CAD assembly files to PRC
* Reload the full model into memory from the previously created PRC files.

.. _sample_translatetopkparts:

Translate to PK Parts
---------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/bridges/TranslateToPkParts

This sample demonstrates how to use the Parasolid bridge in HOOPS Exchange to send the converted CAD data to Parasolid and then use the Parasolid APIs to perform advanced functions on the geometry, like healing, merge, simplify, sew, or accurate edges.

The input is the CAD file path and a directory plus the options. The program generates a Parasolid file from this CAD file. Please note that this sample won't compile right away, specific things (detailed in the header of the source file) related to the Parasolid setup need to be done before running it.

.. _sample_animworkinstruction:

Anim Work Instructions
----------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/AnimWorkinstruction

This sample creates an example Work Instruction from a PDF template by populating text fields and adding JavaScript to buttons to set the camera position and model entity states (visibility and transform) based on viewpoint states stored in the source PRC file.

.. _sample_demodatamodel:

Demo Data Model
---------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/DemoDataModel

Demonstrates how to create a rich interactive PDF without using JavaScript. By pushing data into specific structures and binding data to the layout, rich interactive PDF can be created. Text fields, lists, and scrolling tables can typically be updated automatically depending on what's been selected by the user.

.. _sample_demofunctionalities:

Demo Functionalities
--------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/DemoFunctionalities

This sample application demonstrates how to create a document with different pages inserted from different sources. It also demonstrates the creation of tables on a PDF page.

.. _sample_demofunctionalitiesadv:

Demo Functionalities Advanced
-----------------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/DemoFunctionalitiesAdv

This sample application demonstrates miscellaneous functionalities for Advanced Publishing Advanced.

.. _sample_demolayers:

Demo Layers
-----------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/DemoLayers

This sample application demonstrates how to generate a PDF document with layers using Advanced Publishing.

.. _sample_export3dtohtml:

Export 3D to HTML
-----------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/Export3DToHtml

This sample application demonstrates how to export a 3D model to HTML using Advanced Publishing. The sample shows how to generate a single monolithic HTML file. See the section :doc:`Viewing 3D in the Browser </guide/export/view3d>` in our Programming Guide for more details.

.. _sample_exportpdftohtml:

Export PDF to HTML
------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/ExportPDFToHtml

This sample application demonstrates how to export an interactive 3D PDF to HTML using Advanced Publishing. The sample shows how to generate a root XML file with the associated resources (HTML, JavaScript ...) to be used with an HTTP server. Note that a python script is given to generate files which can be consumed without HTTP server. See the section :doc:`Viewing PDF in the Browser </guide/export/view3d>` in our Programming Guide for more details.

.. _sample_import_publish:

Import Publish
---------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/hello_world/ImportPublish,:doc:`Tutorial </examples/import_publish>`

This sample creates a simple 3D PDF programmatically without using a template.

A detailed version of this sample is provided in :doc:`import_publish`.

.. _sample_manufacturing_mbe:

Manufacturing MBE
-----------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/manufacturing_mbe

Shows how to create a Technical Data Package. It works with 3D annotated models and demonstrates how to insert 3D elements, how to add a view carousel that activates annotation views, and how to attach files (such as STEP files) to create a TDP.

It also demonstrates how to link 2D and 3D content and update what's displayed in some text fields when certain PMI are selected.

.. _sample_pdfwithbomandcarousel:

PDF With BOM and Carousel
-------------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/PDFWithBOMAndCarousel

Demonstrates how to create a scrolling table with 3D assemblies. The scrolling table represents a Bill of Materials. When a line is selected, the 3D part it's linked to is highlighted. Conversely when a 3D node is selected in the scene, the table line it's linked to is highlighted

.. _sample_u3dwithanimation:

U3D With Animation
------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/U3DWithAnimation

Based on a supplied PDF template, this sample shows how to activate an animation in a U3D file with a button click in a PDF form.

.. _sample_updatedata:

Update Data
-----------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/UpdateData

This sample application demonstrates how to update a PDF file generated with Tetra 4D Enrich, using Advanced Publishing. See the section :doc:`Using Tetra 4D Enrich templates </guide/enrich/enrich>` in our Programming Guide for more details.

.. _sample_userdefinedviews:

User Defined Views
------------------

.. csv-table::
   :class: sample-location
   :stub-columns: 1

   C/C++,|he_c_samples_dir|/publishing/UserDefinedViews

This sample demonstrates how to create and activate a simple view that changes camera when clicking on a button.


