wavefront OBJ export error - 'Material' not defined

I’ve tried this with a default install of 2.43 and 2.44. No matter what options I choose in the OBJ export dialog (including normals/high q norms on & off), I always get this same error:
global name ‘Material’ is not defined

I’ve looked through the export_OBJ script and noticed comments about null materials problems. If this is the cause of my issue and is not fixable, would it be possible to alter the script such that only materials that are being used by verts/edges/faces are exported and the nulls are ignored?
Also, I have no problem whatsoever exporting this same mesh from Maya & Max.:confused:

can you try with this script?
Its the latest in SVN and should work with Blender 2.44
also when reporting an error its good to mention the line number .

Ah very cool IdeaMan, thanx for your FAST response! :yes:
Well that seems to have fixed the error but caused two issues. The export gets stuck in a loop. It exports the same obj over and over again. And it doesn’t write the materials file.

You can see the filesizes are the same.

It never writes out the MTL (material) file, I guess because of the loop problem. But the OBJ seems to be proper, so I hand wrote out my own MTL file, and the mesh + materials look good.:smiley:

looks like you have animation export enabled, can you upload or send me the blend. also- if your changing the options, let me know what they are.

You can also avoid uploading screenshots by copying and pasting text from the blender console. - works like all other win32 consoles- see top left hand menu.

Hey Mr. IDM :smiley:
You were correct. I’ve found what appears to be the correct export options:
The confusing part for me was that I was thinking the lightened buttons mean “active” and darkened buttons mean “inactive”, when it’s actually the opposite.:rolleyes:
I truly appreciate your help! :yes:

Hi, when I export objects to the obj format and switch “Copy Images” on I get this error:

Traceback (most recent call last):
  File "<string>", line 641, in write_ui
  File "<string>", line 502, in write
  File "<string>", line 167, in copy_images
NameError: global name 'Material' is not defined

Does anyone know what to do? I want to export objects with texture images.

Not sure when this bug was, but this is fixed in 2.45rc2, Im fairly sure this was fixed in 2.44 also, if its not, you can use 2.45rc

Nope, doesnt work. Ive just tried 2.45rc2 on linux. Build from yesterday. I still get this error:

NameError: global name 'Material' is not defined

As I wrote earlier, it`s only with the “Copy Images” option on. Object export works good, but no texture images are saved to the export file directory.

your running an old script, nowhere in 2.45rc2’s script is Material used in a way that would produce that error.

So what am I doing wrong? I tried that with 2.45rc2 and got this error. How do I use old script with rc2?? What I do is select export, obj and if I turn on “Copy Images” I get error. Without “Copy Images” the script works fine.

to be sure your using the new script. load it up in the text editor an run it.

if that works then remove/backup your old scripts and reinstall blender.


You can solve this problem by editing the export_obj.py in “Blender_Dir/.blender/scripts/” and adding “, Material” at the end of the line 50 : “from Blender import Mesh, Scene, Window, sys, Image, Draw”

Hi cambo,no news about the face index problem?
Every time I export a mesh from Zbrush to blender for posing,in some faces the vertices order get swapped and reimporting it give bad results…
I have found another problem,exporting multiple materials for an object(I use them to do subgroups)change the vertex order too.

blender currently dosnt support keeping the order of face indices’s.
if you want it to work its just make sure the zero vertex has no face users.

for other purposes where the morph target option isnt enough, I suggest you use/write a different obj import/export script that focus on this specific use case. since its too much to fit this into a general purpose import/export script.

The obj import/export tutorials would be a good start for this.

you could write dummy vert support into it. - an importer and exporter that create on import and ignore on export. this would ensure the face order is kept.

I understand,but it’s a pity.You are simply tell me that Zbrush and Blender can’t cooperate,it isn’t a good news…at this point for me it’s easier not using blender,I’m not happy.

This isnt something I have much control over, ZBrush (or other 3rd party apps) have chosen to use the OBJ format in a way it was not documented to be used.

When I wrote the OBJ support in my intention was to have a high level of interoperability with other software, but keeping attributes of file like vertex/face/material order isnt something blender does so well and not easy to ensure work so special care needs to be taken in this case .

Best thing is to write a “ZBrush-OBJ” import and export script, this wont be that hard since you wont need to support OBJ’s from every other app. if you want, start a wiki with the needed features, post an example OBJ and others can help. I dont mind writing the initial version even.

There is at least one another script that works fine with zbrush file. Try to find it.

maintaining the order of verts in a face is not an issue with the script but blender. even if your script SHOULD work fine, blender will re-arrange so the first vert never falls on face.v[2] or face.v[3], this was a bad design decision made in blender early on in its development.

hopefully we will move to a new mesh system called BMesh that has a development branch at the moment,

Should work fine ?

Here an old example : http://cobalt3d.free.fr/images_3dblender/obj_io/nzbrushobj_io.jpg
With the current Blender 2.44, it seems that there is a problem :
but it can be improved…