pythonrenderingblenderpovray

Blender render " location: <unknown location> and " UnboundLocalError " with Pov Ray addon


I am not sure this is the best place the ask but here I go...

I am trying to render an image with the Pov ray addon for Blender 2.79b. When I do so, it just shows me an ugly checkerboard.

After some goofing around I clicked the info tab and it showed me this little message:

Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\render_povray\render.py", line 4147, in render
    self._export(scene, povPath, renderImagePath)
  File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\render_povray\render.py", line 3837, in _export
    write_pov(self._temp_file_in, scene, info_callback)
  File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\render_povray\render.py", line 3648, in write_pov
    shading.writeMaterial(using_uberpov, DEF_MAT_NAME, scene, tabWrite, safety, comments, uniqueName, materialNames, material)
  File "C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\render_povray\shading.py", line 251, in writeMaterial
    if(t and t.use and validPath and
UnboundLocalError: local variable 'validPath' referenced before assignment

location: <unknown location>:-1

I don't really understand Python (or coding in general) unfortunately, so I don't want to touch anything until I understand it better.


Solution

  • Open the file C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons\render_povray\shading.py and replace lines

    if material:
        special_texture_found = False
        for t in material.texture_slots:
            if t and t.use and t.texture is not None:
                if (t.texture.type == 'IMAGE' and t.texture.image) or t.texture.type != 'IMAGE':
                    validPath=True
            else:
                validPath=False
            if(t and t.use and validPath and
               (t.use_map_specular or t.use_map_raymir or t.use_map_normal or t.use_map_alpha)):
                special_texture_found = True
                continue  # Some texture found
    
        if special_texture_found or colored_specular_found:
            # Level=1 Means No specular nor Mirror reflection
            povHasnoSpecularMaps(Level=1)
    
            # Level=3 Means Maximum Spec and Mirror
            povHasnoSpecularMaps(Level=3)
    

    with the following code from the updated add-on for Blender 2.8. Make sure that the identation level is the same as in the original file.

    if material:
        special_texture_found = False
        for t in material.texture_slots:
            if t and t.use and t.texture is not None:
                if (t.texture.type == 'IMAGE' and t.texture.image) or t.texture.type != 'IMAGE':
                    #validPath
                    if(t and t.use and
                       (t.use_map_specular or t.use_map_raymir or t.use_map_normal or t.use_map_alpha)):
                        special_texture_found = True
                        continue  # Some texture found
    
        if special_texture_found or colored_specular_found:
            # Level=1 Means No specular nor Mirror reflection
            povHasnoSpecularMaps(Level=1)
    
            # Level=3 Means Maximum Spec and Mirror
            povHasnoSpecularMaps(Level=3)
    

    The issue in the code is that the if-case if (t.texture.type == 'IMAGE' and t.texture.image) or t.texture.type != 'IMAGE': doesn't have an else case where validPath is set. If that case occurs, then validPath isn't initialized which results in the error you're experiencing.