Working on an Exporter and Require Help

Hey everyone, first post, been working on this for a week trying to navigate through blenders (To me anyways) wave of hurdles to get the information I am looking for.

So far I have a partial exporter working, however a few things I am having a hard time finding a few bits of data and a few things are (supposedly) outputting incorrectly. I have tried googling around and have visited quiet a few websites and forums looking for the answers i have been looking for but with no avail.

So last but not least, my question/s.

  1. How can I get it to write a line if there is no parent to a joint? Everything I have tried comes up as a Attribute error: NoneType.

  2. The model I am testing with both blender and milkshape3D(I wrote the exporter for milkshape as well) the values are coming up incorrectly. I have provided code below as a visual (Im not expecting people to write for me, wheres the fun in that)

  3. Havent the slightest clue on how to get a material list as of this moment, with that said I haven’t personally looked for information so I’m not worried about an answer but one is appreciated.


try:
		bpy.ops.object.mode_set(mode='EDIT', toggle=False)
		bpy.ops.mesh.quads_convert_to_tris()
		bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
	except:
		print('No Quads to transform! Good to go!')
	#me = meshes, jo = joints
	
	for obj in bpy.context.selectable_objects:
		me = obj.data
		
		if obj.type == 'ARMATURE':
			fw('jointstart
')
			for bone in me.bones:
				getBoneRot = bone.matrix_local.to_euler()
				fw(bone.name + '
')
				fw('%.6f %.6f %.6f %.6f %.6f %.6f
' % (bone.vector.x, bone.vector.y, bone.vector.z, getBoneRot.x, getBoneRot.y, getBoneRot.z))
				
			fw('jointend
')
		elif obj.type == 'MESH':
			for face in me.faces:
				
				try:
					uv_layer = me.uv_textures.active.data
				except:
					print('do nothing')
				try:
					u1 = uv_layer[face.index].uv1[0]
					v1 = 1.0 - uv_layer[face.index].uv1[1]
				except:
					u1 = 0.0
					v1 = 0.0
				try:
					u2 = uv_layer[face.index].uv2[0]
					v2 = 1.0 - uv_layer[face.index].uv2[1]
				except:
					u2 = 0.0
					v2 = 0.0
				try:
					u3 = uv_layer[face.index].uv3[0]
					v3 = 1.0 - uv_layer[face.index].uv3[1]
				except:
					u3 = 0.0
					v3 = 0.0
				
				fw('
xyz=%i %.6f %.6f %.6f norm=%.6f %.6f %.6f uv=%.6f %.6f' % (me.vertices[face.vertices[0]].groups[0].group, 
																					me.vertices[face.vertices[0]].co.x, 
																					me.vertices[face.vertices[0]].co.y, 
																					me.vertices[face.vertices[0]].co.z , 
																					me.vertices[face.vertices[0]].normal.x , 
																					me.vertices[face.vertices[0]].normal.y , 
																					me.vertices[face.vertices[0]].normal.z, u1, v1))
																					
				fw('
xyz=%i %.6f %.6f %.6f norm=%.6f %.6f %.6f uv=%.6f %.6f' % (me.vertices[face.vertices[1]].groups[0].group , 
																					me.vertices[face.vertices[1]].co.x, 
																					me.vertices[face.vertices[1]].co.y, 
																					me.vertices[face.vertices[1]].co.z , 
																					me.vertices[face.vertices[1]].normal.x , 
																					me.vertices[face.vertices[1]].normal.y , 
																					me.vertices[face.vertices[1]].normal.z, u2, v2))
																					
				fw('
xyz=%i %.6f %.6f %.6f norm=%.6f %.6f %.6f uv=%.6f %.6f' % (me.vertices[face.vertices[2]].groups[0].group , 
																					me.vertices[face.vertices[2]].co.x, 
																					me.vertices[face.vertices[2]].co.y, 
																					me.vertices[face.vertices[2]].co.z , 
																					me.vertices[face.vertices[2]].normal.x , 
																					me.vertices[face.vertices[2]].normal.y , 
																					me.vertices[face.vertices[2]].normal.z, u3, v3))
	

Thanks in advance for the help on my issues :slight_smile:

Hi, maybe this helps:
1.) if you get an error NonType something is (I think) None so test if myThing == None: #no parent?!

Other way of working is to find out yourself as follows:
e.g. Open in blender the Scripting to see a Python window (or whatever way you choose to open such a window)
Now I have a Cube with a material and I am doing this in the Python window (Cube seleted)

cube = C.active_object
cube.m (an now typing Ctrl-space ) and you see a list of what a cube. can give you and there it is: material_slots !!!
so I would investigate furhter: ms = cube.material_slots and then dir(ms) and then got to the help Python Api reference and you know what to search for …

Hey thanks for the reply!

so for the parent bone i just threw it into a try except statement, if it fails and goes to the except just prints null (or whatever I choose)

Like i said i believe the xyz values are incorrect on the joints and faces… however just loaded the model file into the game and all is well for the mesh itself(dont know about joints we shall see within the next couple days)

Must say being able to use the python console in blender is a godsend for finding stuff out. (considering I dont find the blender python wiki very much help, most of it references to old styles (unless im missing something?)

now as for the materials (which i have the data exporting properly as far as I know anyways) the only thing I need to figure out is the directory the textures are in. any possible way?

Once again thanks!