# How-To: Use BuildMasterAssemblyModel function

**URL:** <https://forum.techsoft3d.com/t/how-to-use-buildmasterassemblymodel-function/1346>\
**Category:** HOOPS Visualize Web\
**Tags:** code, learn, knowledge-base, how-to, authoring\
**Created:** [October 16, 2021, 4:00am UTC](https://forum.techsoft3d.com/t/how-to-use-buildmasterassemblymodel-function/1346 "2021-10-16T04:00:00Z")\
**Posts on this page:** 1\
**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:** [October 16, 2021, 4:00am UTC](https://forum.techsoft3d.com/t/how-to-use-buildmasterassemblymodel-function/1346/1 "2021-10-16T04:00:00Z")

</div>

`SC::Store::AssemblyTree::BuildMasterAssemblyModel` will gather part modes and create the master assembly model.

Sample Code

1. There are two models, microengine1.scz and microengine2.scz, in C:\HOOPS\_Communicator\quick\_start\converted\_models\authoring\_samples\_data
2. Combine two models and create a assembly model “combine\_microengine\_sample”.

```auto
int
CombineSample(const std::string& model_path)
{
	std::string cache_path = "C:\\HOOPS_Communicator_2021\\quick_start\\converted_models\\authoring_samples_data";
	std::string model_name = "combine_microengine_sample";

	ApplicationLogger logger;
	try {
		// Open the cache
		SC::Store::Database::SetLicense(HOOPS_LICENSE);
		SC::Store::Cache cache = SC::Store::Database::Open(logger);

		SC::Store::AssemblyTree assembly_tree(logger);
		uint32_t root_id = 0;
		assembly_tree.CreateAssemblyTreeRoot(root_id);
		assembly_tree.SetNodeName(root_id, "assemblytree_sample");
		uint32_t child_node = 0;
		assembly_tree.CreateChild(root_id, child_node);
		assembly_tree.SetNodeName(child_node, "first");
		bool res = assembly_tree.SetExternalModel(child_node, "microengine1");

		float matrix_data[] = {
			1.0f, 0.0f, 0.0f,
			0.0f, 1.0f, 0.0f,
			0.0f, 0.0f, 1.0f,
			0.0f, 100.0f, 0.0f,
		};
		SC::Store::Matrix3d * matrix = (SC::Store::Matrix3d *)matrix_data;

		assembly_tree.CreateChild(root_id, child_node);
		assembly_tree.SetNodeName(child_node, "second");
		res = assembly_tree.SetExternalModel(child_node, "microengine2");
		assembly_tree.SetNodeLocalTransform(child_node, *matrix);

		std::string modelPath = cache_path + "\\" + model_name;
		if (cache.Exists((cache_path + "\\" + model_name).c_str())) {
			printf("Model already exists.\n");
			return 1;
		}
		res = assembly_tree.BuildMasterAssemblyModel(cache_path.c_str(), modelPath.c_str(), cache_path.c_str(), false);
	}
	catch (std::exception const & e)
	{
		std::string message("Exception: ");
		message.append(e.what());
		message.append("\n");
		logger.Message(message.c_str());
		return 1;
	}

	return 0;
}

```

 ![image-20211207-073253](https://us1.discourse-cdn.com/flex020/uploads/techsoft3d/original/1X/194e2716fc6488404c0e0d0b5eb87594bf8cd1f7.png)
