# How to load external material for pathtracer from python

**URL:** https://discourse.paraview.org/t/how-to-load-external-material-for-pathtracer-from-python/5426
**Category:** ParaView Support
**Created:** [September 25, 2020, 12:23pm UTC](https://discourse.paraview.org/t/how-to-load-external-material-for-pathtracer-from-python/5426 "2020-09-25T12:23:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pcrepier](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/f4b2a3/32.png) [@pcrepier](https://discourse.paraview.org/u/pcrepier)
#### Post date: [September 25, 2020, 12:23pm UTC](https://discourse.paraview.org/t/how-to-load-external-material-for-pathtracer-from-python/5426/1 "2020-09-25T12:23:58Z")

</div>

Hi Everyone,

I while back I read on one of the threads that materials could be imported from python using that feature:

```auto
materialLibrary1 = GetMaterialLibrary()
materialLibrary1.LoadMaterials = <file>

```

I tried providing my json file containing my materials (provide the file path), but with no succes.  
Or should that be the actual file object from open(‘path/to/my/file.json’) ?

Can someone give a bit more details about how to use this ?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![Dave\_DeMarle](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dave_demarle/32/27_2.png) [@Dave\_DeMarle](https://discourse.paraview.org/u/Dave_DeMarle)
#### Post date: [September 27, 2020, 7:50pm UTC](https://discourse.paraview.org/t/how-to-load-external-material-for-pathtracer-from-python/5426/2 "2020-09-27T19:50:38Z")

</div>

It should be the filename of the json file, not the file object. Do you get any error or warning messages when you try?

I tested 5.8.1 on windows a moment ago by downloading ParaView and renaming the materials directory. I could load the misplaced materials both from View-\>Python Shell and from pvpython, so there must be something different about our setups.

---

<div class="post-metadata">

### Author: ![pcrepier](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/f4b2a3/32.png) [@pcrepier](https://discourse.paraview.org/u/pcrepier)
#### Post date: [September 28, 2020, 6:36am UTC](https://discourse.paraview.org/t/how-to-load-external-material-for-pathtracer-from-python/5426/3 "2020-09-28T06:36:59Z")

</div>

That what I did in the first place.  
I also checked that the path I provided exists, which is the case.  
ParaView does not complain about anything until the render happens.  
Then I get an error that the material does not exists and it reverts to the default obj material.  
I tried with 5.8.0, not 5.8.1 though, and on linux.  
I’ll try with 5.8.1 in case this was solved in that release.  
Or is it an issue with the linux release ?

---

<div class="post-metadata">

### Author: ![Dave\_DeMarle](https://discourse.paraview.org/user_avatar/discourse.paraview.org/dave_demarle/32/27_2.png) [@Dave\_DeMarle](https://discourse.paraview.org/u/Dave_DeMarle)
#### Post date: [September 28, 2020, 7:47am UTC](https://discourse.paraview.org/t/how-to-load-external-material-for-pathtracer-from-python/5426/4 "2020-09-28T07:47:01Z")

</div>

I tested ParaView 5.8.0 on linux and was able to change materials from python too.

I suspect a mismatch in the path or the material names, either in your script or in your json file.

Try what you are doing from within View-\>Python Shell in the gui. Change the material filename, to force the property to update , load the materials file, and then render. Does the list of available material change or not? If not then something is going wrong with the path. If the list does change then something is wrong with the script or the file itself.

In my case when I refer to a material that isn’t in the file (“water” instead of “Water” here):

r.OSPRayMaterial = "Water’

I get this message on the Render() call:

Warning: unrecognized material “”, using a default OBJMaterial

Meanwhile when my json file has an invalid material (“nonexistentmaterial” here) in it I get the following when I go to use it:

Warning: unrecognized material “nonexistentmaterial”, using a default OBJMaterial

hth

---

<div class="post-metadata">

### Author: ![pcrepier](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/f4b2a3/32.png) [@pcrepier](https://discourse.paraview.org/u/pcrepier)
#### Post date: [September 30, 2020, 1:56pm UTC](https://discourse.paraview.org/t/how-to-load-external-material-for-pathtracer-from-python/5426/5 "2020-09-30T13:56:51Z")

</div>

After some more searching I finally figured it out!

The trick that my script resets the session at every loop, and that seemed to be conflicting with materials library.

if I set the materials at every loop before the rendering, then it just works.  
tried with 5.8.0 with success.

So, case closed!
