# How to use HOOPS Exchange with LibConverter for Stream Cache export

**URL:** <https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501>\
**Category:** HOOPS Exchange\
**Tags:** code, knowledge-base, how-to\
**Created:** [January 13, 2022, 5:00am UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501 "2022-01-13T05:00:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabriel.peragine](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/gabriel.peragine/32/1535_2.png) [@gabriel.peragine](https://forum.techsoft3d.com/u/gabriel.peragine)\
**Post date:** [January 13, 2022, 5:00am UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501/1 "2022-01-13T05:00:00Z")

</div>

If you are using HOOPS Communicator, you may want to take advantage of HOOPS Exchange’s advanced functions and conversion options before generating a Stream Cache model.

## How-To

As you may know, LibConverter is a simple API included in the HOOPS Communicator package. `converter.exe` is actually using this API.  
The project mini\_converter is a good start point to use this API: `HOOPS_Communicator\authoring\converter\example\sample_projects\mini_converter`

- The workflow you want to implement is:

`CAD File -> [HOOPS Exchange C API] -> PRC ModelFile -> [LibConverter] -> SCS file`

The most important API to know to implement this workflow is in LibConvert: [bool Communicator::Importer::Load (void \* modelFile )](https://docs.techsoft3d.com/hoops/visualize-web/api_ref/data_import/libconverter/classCommunicator_1_1Importer.html#_CPPv4N12Communicator8ImporterE)

## Implementation

This is what you are going to do:

- Initialize HOOPS Exchange C API
- Import the CAD file using HOOPS Exchange in a PRC buffer `A3DAsmModelFile*`
- Do whatever you want to `A3DAsmModelFile*` using HOOPS Exchange
- Initialize LibConverter
- Import the PRC buffer `A3DAsmModelFile*`
- Export it to SCS

To initialize and use HOOPS Exchange, you can review the sample ImportExport from the HOOPS Exchange package.  
The class `A3DSDKHOOPSExchangeLoader` makes it easier to use the API, and we show how to use it in our [programming guide](https://docs.techsoft3d.com/hoops/exchange/guide/basic_operations/load_model.html).

```auto
A3DSDKHOOPSExchangeLoader sHoopsExchangeLoader(_T(HOOPS_BINARY_DIRECTORY));
A3DImport sImport(acSrcFileName); // see A3DSDKInternalConvert.hxx for import and export detailed parameters
CHECK_RET(sHoopsExchangeLoader.Import(sImport));

```

After you call the Import function, the PRC buffer will be in sHoopsExchangeLoader.m\_psModelFile  
So you can use later LibConverter like this:

```auto
SC_Import_Options importOptions; 
importer.Load(sHoopsExchangeLoader.m_psModelFile);

SC_Export_Options exportOptions; // Export SSC
exporter.WriteSC(nullptr, output.c_str(), exportOptions);

```

## Sample

I don’t like using `A3DSDKHOOPSExchangeLoader` because this structure hides the actual call to the API. It makes it simpler, but it requires more includes that if you just do the direct calls. I think it makes the sample easier to read.

Here is a sample to demonstrate the implementation described above. To use it:

- Replace the code from `HOOPS_Communicator_2022_XX\authoring\converter\example\sample_projects\mini_converter\mini.cpp`
- Add in additional include directories the path to `HOOPS_Exchange_Publish_2022_XX\include`
- Replace the path in the code (Commented with TODO when there is something to change )

```auto
#include "libconverter.h"
using namespace Communicator;

///TODO: Add the Additional include directory = "[...]/HOOPS_Exchange_Publish_2022_XX\include"
#define INITIALIZE_A3D_API
#include <A3DSDKIncludes.h>

#include <string>
using namespace std;

int
main(int argc, char* argv[])
{
///TODO: the license variable is not used, you may pass "" as the first argument. 
///USAGE: ./mini_converter "" "CAD/FILE/INPUT.CAD" "PATH/TO/SCS.SCS" 
    string input, output; // Obtain the input and output filenames
    size_t n = 1; // Skip verb
    if (n < argc)
        input = argv[n++];
    if (n < argc)
        output = argv[n++];

    // Initiliaze HOOPS Exchange 
///TODO: REPLACE THE PATH TO BIN\\WIN64_VC140
    A3DStatus iRet;
    if (!A3DSDKLoadLibrary("HOOPS_Exchange_Publish_2022_SP1_U1\\bin\\win64_v140"))
        return A3D_ERROR;

///TODO: I'm using directly the HOOPS_LICENSE variable defined in hoops_license.h. The license you generate on our developer zone is unified, 
//that means it works with HOOPS COmmunicator, HOOPS Exchange, LibConverter, etc... 
  
    A3DLicPutUnifiedLicense(HOOPS_LICENSE);

    A3DInt32 iMajorVersion = 0, iMinorVersion = 0;
    iRet = A3DDllGetVersion(&iMajorVersion, &iMinorVersion);
    if (iRet != A3D_SUCCESS)
        return iRet;

    iRet = A3DDllInitialize(A3D_DLL_MAJORVERSION, A3D_DLL_MINORVERSION);
    if (iRet != A3D_SUCCESS)
        return iRet;

    // Import 

    A3DAsmModelFile* m_psModelFile;

    A3DRWParamsLoadData m_sLoadData;
    
    A3D_INITIALIZE_DATA(A3DRWParamsLoadData, m_sLoadData);
    m_sLoadData.m_sGeneral.m_bReadSolids = true;
    m_sLoadData.m_sGeneral.m_bReadSurfaces = true;
    m_sLoadData.m_sGeneral.m_bReadWireframes = true;
    m_sLoadData.m_sGeneral.m_bReadPmis = true;
    m_sLoadData.m_sGeneral.m_bReadAttributes = true;
    m_sLoadData.m_sGeneral.m_bReadHiddenObjects = true;
    m_sLoadData.m_sGeneral.m_bReadConstructionAndReferences = false;
    m_sLoadData.m_sGeneral.m_bReadActiveFilter = true;
    m_sLoadData.m_sGeneral.m_eReadingMode2D3D = kA3DRead_3D;
    m_sLoadData.m_sGeneral.m_eReadGeomTessMode = kA3DReadGeomAndTess;
    m_sLoadData.m_sGeneral.m_eDefaultUnit = kA3DUnitUnknown;
    m_sLoadData.m_sTessellation.m_eTessellationLevelOfDetail = kA3DTessLODMedium;
    m_sLoadData.m_sAssembly.m_bUseRootDirectory = true;
    m_sLoadData.m_sMultiEntries.m_bLoadDefault = true;
    m_sLoadData.m_sPmi.m_bAlwaysSubstituteFont = false;
    m_sLoadData.m_sPmi.m_pcSubstitutionFont = (char*)"Myriad CAD";

     iRet = A3DAsmModelFileLoadFromFile(input.c_str(), &m_sLoadData, &m_psModelFile);
    if (iRet != A3D_SUCCESS)
        return iRet;

// HERE YOU CAN PROCESS m_psModelFile WITH HOOPS EXCHANGE ADVANCED FUNCTION 

    Converter converter; // License Registration
    converter.Init(HOOPS_LICENSE);

    Importer importer; // Import Initialization
    if (!importer.Init(&converter))
        return EXIT_FAILURE;

    //Import the PRC buffer directly
    SC_Import_Options importOptions; // Import
    if (!importer.Load(m_psModelFile))
        return EXIT_FAILURE;

    Exporter exporter; // Export Initialization
    if (!exporter.Init(&importer))
        return EXIT_FAILURE;

   
    SC_Export_Options exportOptions; // Export Stream Cache Model
    //export SCS 
    if (!exporter.WriteSC(nullptr, output.c_str(), exportOptions))
        return EXIT_FAILURE;

    return EXIT_SUCCESS;
}

```

With this workflow, you have complete access to m\_sLoadData (the import options). It includes more parameters than converter.exe.

You can also process the model before export (for example, Sewing to repair BRep).

---

<div class="post-metadata">

**Author:** ![136638675](https://avatars.discourse-cdn.com/v4/letter/1/e47c2d/32.png) [@136638675](https://forum.techsoft3d.com/u/136638675)\
**Post date:** [February 10, 2023, 8:19am UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501/2 "2023-02-10T08:19:50Z")

</div>

I can’t execute this in linux, I can compile this, but when I run the app, it reports segmentFault.

---

<div class="post-metadata">

**Author:** ![gabriel.peragine](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/gabriel.peragine/32/1535_2.png) [@gabriel.peragine](https://forum.techsoft3d.com/u/gabriel.peragine)\
**Post date:** [February 16, 2023, 7:06pm UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501/3 "2023-02-16T19:06:25Z")

</div>

Hey @136638675 –

First off, welcome to the forum!

Secondly, I shared your feedback with the original post author @kevin . 🙂

---

<div class="post-metadata">

**Author:** ![kevin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/kevin/32/580_2.png) [@kevin](https://forum.techsoft3d.com/u/kevin)\
**Post date:** [February 17, 2023, 9:47am UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501/4 "2023-02-17T09:47:38Z")

</div>

Hello,

This code is for Windows. On Linux you need to make sure you are loading the library from the Linux binaries of HOOPS Exchange. These binaries in the HOOPS Exchange installation folder, in bin/linux64.

Also, be careful to be using the compatible version of HOOPS Exchange with HOOPS Communicator. If you are running HOOPS Communicator 2023, you want to work with HOOPS Exchange 2023 as well.

I hope it helps.  
-Kevin

---

<div class="post-metadata">

**Author:** ![guillaume.robichaud](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@guillaume.robichaud](https://forum.techsoft3d.com/u/guillaume.robichaud)\
**Post date:** [March 10, 2023, 3:56pm UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501/5 "2023-03-10T15:56:23Z")

</div>

Any chance the Communicator’s converter supporting other formats? The converter or the libconverter don’t seem to be inline with this list ([File Formats — HOOPS Exchange 2023 U1 documentation](https://docs.techsoft3d.com/exchange/latest/start/supported-formats.html)).

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/guido/32/115_2.png) [@guido](https://forum.techsoft3d.com/u/guido)\
**Post date:** [March 10, 2023, 4:34pm UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501/6 "2023-03-10T16:34:25Z")

</div>

Hi,

for the most part HOOPS Communicator should be able to read all formats that the version of HOOPS Exchange it is using (which is listed in the release notes) supports, independent of what is listed in the Communicator documentation. If you see that not being the case, please let us know.

The Communicator docs not being in line with the Exchange does is something we need to  
address of course. Can you point us to an inconsistency there?

---

<div class="post-metadata">

**Author:** ![guillaume.robichaud](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@guillaume.robichaud](https://forum.techsoft3d.com/u/guillaume.robichaud)\
**Post date:** [March 10, 2023, 4:54pm UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501/7 "2023-03-10T16:54:46Z")

</div>

Reading is not the issue. We already convert files into SCS/PRC using the converter. We wanted to add a GLTF to the list for marketing purposes.

---

<div class="post-metadata">

**Author:** ![guido](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/guido/32/115_2.png) [@guido](https://forum.techsoft3d.com/u/guido)\
**Post date:** [March 10, 2023, 5:08pm UTC](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501/8 "2023-03-10T17:08:34Z")

</div>

You are referring to _exporting_ to other formats than the ones currently supported by converter/libconverter?

In the medium term the plan is to allow for that via a new XML based interface to converter which would give access to nearly all HOOPS Exchange settings and export formats. In the short-term, if you are interested in gltf export, please make a feature request in our support portal.

It is also worth noting that if you license the HOOPS Web Platform, you already have access to HOOPS Exchange, so you could write our own exporter as well. Reading a CAD file (or a prc file) and exporting it to GLTF only requires a few lines of code in HOOPS Exchange.
