# How to create shattered assembly parts & XML from monolithic assembly

**URL:** <https://forum.techsoft3d.com/t/how-to-create-shattered-assembly-parts-xml-from-monolithic-assembly/2719>\
**Category:** HOOPS Visualize Web\
**Tags:** sample, exchange, learn, knowledge-base, how-to\
**Created:** [October 4, 2023, 6:14am UTC](https://forum.techsoft3d.com/t/how-to-create-shattered-assembly-parts-xml-from-monolithic-assembly/2719 "2023-10-04T06:14:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Toshi-TS3D](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/toshi-ts3d/32/885_2.png) [@Toshi-TS3D](https://forum.techsoft3d.com/u/Toshi-TS3D)\
**Post date:** [October 4, 2023, 6:14am UTC](https://forum.techsoft3d.com/t/how-to-create-shattered-assembly-parts-xml-from-monolithic-assembly/2719/1 "2023-10-04T06:14:41Z")

</div>

# Introduction

Although shattered assembly can be created from some native CAD formats whose sub-components reside in individual files such as CATIA V5, Creo - Pro/E, NX or SolidWorks, it is not possible to create from a monolithic assembly file such as IFC, Revit or 3DXML.  
This article introduces a sample which creates shattered assembly from a monolithic assembly file using HOOPS Exchange and LibConverter of HOOPS Communicator. Created shattered parts and master XML file can be loaded using HOOPS Communicator WebViewer APIs: `loadSubtreeFromXmlFile` and `loadSubtreeFromScsXmlFile`

 ![shattered](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/6/6ea065621a3ecb5a8ac05c13075e676cee2f5774.jpeg)

You can study advantage of the shattered approach over the monolithic workflow from [here](https://docs.techsoft3d.com/communicator/latest/prog_guide/viewing/data_model/stream_cache/shattered-workflows.html?highlight=shatterd)

# Sample project

Download sample project from following Git repository:

> **[GitHub - toshi-bata/shattered: This sample creates shattered assembly from a...](https://github.com/toshi-bata/shattered)**
>
> This sample creates shattered assembly from a monolithic assembly file using HOOPS Exchange and LibConverter of HOOPS Communicator.

# Setup and Usage

Please refer `README.MD` in the Git repository.

# Tips

## HOOPS Exchange with LibConverter

This sample imports a monolithic assembly file and traversed it using HOOPS Exchange. The traverse process exports a master XML file and create individual part models. Part models are converter to SC (SCZ) and SCS files using LibConverter of HOOPS Communicator.

 ![shattered-2](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/2X/2/24d479bafacbd4f145cf0cc14ce0fa127d61ead5.png)

Usage of HOOPS Exchange with LibConverter is introduced [here](https://forum.techsoft3d.com/t/how-to-use-hoops-exchange-with-libconverter-for-stream-cache-export/1501)

## Traverse model file using Visitor pattern

This sample uses Visitor pattern contained in HOOPS Exchange samples to traverse imported model.  
Usage of the the Visitor pattern is introduced [here](https://forum.techsoft3d.com/t/how-to-traverse-a-prc-model-file-using-visitor-pattern-for-rapid-prototyping/1456)

## Instanced parts

Instanced parts are only represented once but show up multiple times in the hierarchy.  
By setting `false` to `SetTraverseInstance`, the Visitor pattern accesses only the first part instance so that it creates a part SC of instanced parts.

```auto
	A3DVisitorContainer sA3DVisitorContainer(CONNECT_TRANSFO);
	sA3DVisitorContainer.SetTraverseInstance(false);

```

## ProductOccurrence deep copy

It is necessary to create a copy of part ProductOccurrence using `A3DAsmProductOccurrenceDeepCopy` before creating individual part PRC.

```auto
	A3DAsmProductOccurrence* pCopyPO;
	iRet = A3DAsmProductOccurrenceDeepCopy(pPartPO, &pCopyPO);

```

(Same part ProductOccurrence cannot be refereed from both master and part model files)

---

<div class="post-metadata">

**Author:** ![Toshi-TS3D](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.techsoft3d.com/toshi-ts3d/32/885_2.png) [@Toshi-TS3D](https://forum.techsoft3d.com/u/Toshi-TS3D)\
**Post date:** [April 8, 2024, 3:48am UTC](https://forum.techsoft3d.com/t/how-to-create-shattered-assembly-parts-xml-from-monolithic-assembly/2719/2 "2024-04-08T03:48:52Z")

</div>

Since a new usability API: Tree Traversal API was released in the HOOPS Exchange 2024, I’ve added a new sample project (convertScShattered\_TreeNode) in the GitHub using the new APIs instead of Visitor pattern.  
[https://docs.techsoft3d.com/exchange/latest/guide/tree\_traversal.html](https://docs.techsoft3d.com/exchange/latest/guide/tree_traversal.html)
