# obj-mtl-importer.py errors

**URL:** https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309
**Category:** ParaView Support
**Tags:** python, vtk
**Created:** [September 9, 2020, 4:58pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309 "2020-09-09T16:58:37Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![RvdN](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@RvdN](https://discourse.paraview.org/u/RvdN)
#### Post date: [September 9, 2020, 4:58pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309/1 "2020-09-09T16:58:37Z")

</div>

I am currently experimenting to visualise some 3D GIS data within Paraview,  
I am currently able to open en visualise my obj files within ParaView GUI but I would also like to import the mtl files.

To achieve that I thought to create a state file based on the obj and mtl file using the obj-mtl-importer.py [script link](https://github.com/Kitware/vtk-js/blob/master/Utilities/ParaView/obj-mtl-importer.py).

Unfortunately, I am getting multiple errors when I try to use the provided script:

1. the first error is an attribute error in line 227 key.sort() full error:  
Traceback (most recent call last):  
File “obj-mtl-importer.py”, line 414, in   
loadScene(objPath, ’s.mtl' objPath[:-4])  
File “obj-mtl-importer.py”, line 384, in loadScene  
mtlReader.reduceMaterialDefinitions()  
File “obj-mtl-importer.py”, line 269, in reduceMaterialDefinitions  
sha = materialToSHA(self.materials[name])  
File “obj-mtl-importer.py”, line 227, in materialToSHA  
keys.sort()  
AttributeError: ‘dict\_keys’ object has no attribute ‘sort’

Ass I understood, it is not possible to use the sort function anymore in python3, therefore, I changed line 227 into: sorted(keys).  
This worked but then I god a second error:

1. Encoding error, encoded before hashing line 230 full error:  
Traceback (most recent call last):  
File “obj-mtl-importer.py”, line 414, in   
loadScene(objPath, ’s.mtl' objPath[:-4])  
File “obj-mtl-importer.py”, line 384, in loadScene  
mtlReader.reduceMaterialDefinitions()  
File “obj-mtl-importer.py”, line 269, in reduceMaterialDefinitions  
sha = materialToSHA(self.materials[name])  
File “obj-mtl-importer.py”, line 230, in materialToSHA  
m.update(key)  
TypeError: Unicode-objects must be encoded before hashing

I changed line 230 and 232 into respectively: m.update(key.encode(‘utf-8’)) and m.update(token.encode(‘utf-8’))  
This passed but then I have a third error

1. typeError: line 65. full error:  
Reducing materials from 330 to 329  
Traceback (most recent call last):  
File “obj-mtl-importer.py”, line 414, in   
loadScene(objPath, ’s.mtl' objPath[:-4])  
File “obj-mtl-importer.py”, line 386, in loadScene  
objReader = OBJParser(objFilePath, ‘usemtl’)  
File “obj-mtl-importer.py”, line 58, in **init**  
self.end();  
File “obj-mtl-importer.py”, line 180, in end  
polydata.SetPoints(OBJParser.createPoints(pts))  
File “obj-mtl-importer.py”, line 65, in createPoints  
pts.SetNumberOfPoints(nbPoints);  
TypeError: SetNumberOfPoints argument %Id: %V

I have no idea what this error means, and if it can be because I did something wrong while trying to fix the earlier bugs? anybody and idea what is going wrong/ what I should change?

Running windows 10 home  
vtk-js-14.15.7  
paraview 5.8.1  
python 3.7

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [September 9, 2020, 7:18pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309/2 "2020-09-09T19:18:38Z")

</div>

Thanks for reporting the issue. I just push a fixed in the vtk-js python script.

The link you are providing is now working with ParaView 5.8/Python3.

---

<div class="post-metadata">

### Author: ![RvdN](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@RvdN](https://discourse.paraview.org/u/RvdN)
#### Post date: [September 10, 2020, 3:44pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309/3 "2020-09-10T15:44:11Z")

</div>

Thank you for the fix, I can run the script without any errors now,

However, when I load the created pvsm file into ParaView, I don’t get to see anything. The pipeline browser is showing all the individual vtp files, but the viewer screen remains white. Can this be an error in the script? or is this something specific to my obj and mtl file?

 ![image](https://discourse.paraview.org/uploads/default/original/2X/2/2280bdf1cbcc871ebfb2b3c8d9edba6566578bba.png)

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [September 10, 2020, 4:26pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309/4 "2020-09-10T16:26:25Z")

</div>

That seems to be an issue with PV, but if you load something else like a “Cone”, the view will show up. At that point, you will be able to delete that extra Cone.

---

<div class="post-metadata">

### Author: ![RvdN](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@RvdN](https://discourse.paraview.org/u/RvdN)
#### Post date: [September 10, 2020, 5:35pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309/5 "2020-09-10T17:35:18Z")

</div>

Your workaround does not work for me, but not sure why yet.

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [September 10, 2020, 7:46pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309/6 "2020-09-10T19:46:43Z")

</div>

You mean that after loading your state file, adding a source does not make the 3D view show up?

---

<div class="post-metadata">

### Author: ![RvdN](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/r/6bbea6/32.png) [@RvdN](https://discourse.paraview.org/u/RvdN)
#### Post date: [September 10, 2020, 8:20pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309/7 "2020-09-10T20:20:30Z")

</div>

Yes, So I am loading the state file, and then I open one of the paraview example sets like can or disk\_out\_ref but, the 3D will not show up then. This should work, right? or did I miss understand your workaround description?

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [September 10, 2020, 8:44pm UTC](https://discourse.paraview.org/t/obj-mtl-importer-py-errors/5309/8 "2020-09-10T20:44:29Z")

</div>

That should be it, that worked for me on macOS.
