# Restore visual properties of models when registered as Sample Data

**URL:** <https://discourse.slicer.org/t/restore-visual-properties-of-models-when-registered-as-sample-data/21654>\
**Category:** Development\
**Created:** [January 27, 2022, 2:44pm UTC](https://discourse.slicer.org/t/restore-visual-properties-of-models-when-registered-as-sample-data/21654 "2022-01-27T14:44:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [January 27, 2022, 2:44pm UTC](https://discourse.slicer.org/t/restore-visual-properties-of-models-when-registered-as-sample-data/21654/1 "2022-01-27T14:44:17Z")

</div>

I’m using `SampleData` to register sample data to be used in Slicer-Liver. Part of that data is 3D models, which don’t preserve the visual properties when saved as `.vtk` models. Is there anyway to set up the visual properties of these models automatically when they are loaded again? Thanks!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 27, 2022, 2:48pm UTC](https://discourse.slicer.org/t/restore-visual-properties-of-models-when-registered-as-sample-data/21654/2 "2022-01-27T14:48:48Z")

</div>

You can use an .mrb file as sample data, which contains the VTK models and all the display properties. If you want you can keep only the model, storage, and display node in the .mrml file (in the mrb zip file) and remove everything else (such as layout node, slice nodes, etc. that would update a bunch of other things when the mrb file is loaded).

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [January 27, 2022, 2:51pm UTC](https://discourse.slicer.org/t/restore-visual-properties-of-models-when-registered-as-sample-data/21654/3 "2022-01-27T14:51:17Z")

</div>

Thanks @lassoan. I wonder if it would be an option to add a new parameter in `SampleData.SampleDataLogic.registerCustomSampleDataSource` with a list of setup functions to be called after the data is loaded.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 27, 2022, 2:55pm UTC](https://discourse.slicer.org/t/restore-visual-properties-of-models-when-registered-as-sample-data/21654/4 "2022-01-27T14:55:11Z")

</div>

See example in SampleData.py:

```auto
    filePaths = logic.downloadFromSource(SampleDataSource(
      uris=TESTING_DATA_URL + 'SHA256/5a1c78c3347f77970b1a29e718bfa10e5376214692d55a7320af94b9d8d592b8',
      loadFiles=True, fileNames='slicer4minute.mrb'))

```

You need to set `loadFiles=True` to load the .mrb file (by default it is only downloaded).

> [@RafaelPalomar](#):
>
> I wonder if it would be an option to add a new parameter in `SampleData.SampleDataLogic.registerCustomSampleDataSource` with a list of setup functions to be called after the data is loaded.

You can do this by specifying a custom loader function. I would not recommend to use it for modifying the loaded data, setting display properties, etc., as it would make the result hard to reproduce. The outcome would depend on both the data on the server and the loading script: two different locations, two different ways of specifying data.

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [January 27, 2022, 2:56pm UTC](https://discourse.slicer.org/t/restore-visual-properties-of-models-when-registered-as-sample-data/21654/5 "2022-01-27T14:56:18Z")

</div>

I see. Thanks a lot @lassoan!
