obj-mtl-importer.py errors

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.

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

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.

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?

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.

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

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

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?

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