Previous Thread  Next Thread

chat icon string error

dotblend

Posted: Tue Nov 19, 2002 11:55 am
Joined: 17 Oct 2002
Posts: 72
i get this error, what is wrong????

File "<string>", line 140
wrlexport = VrmlExport("str(Blender.Get("Curframe"))+ "test.wrl")
^

entire script here:


import Blender210
import string

class VrmlExport:
def __init__(self, filename):
self.file = open(filename, "w")

def export(self, scene):
print "exporting ..."
self.writeHeader()
for name in scene.objects:
object = Blender210.getObject(name)
if object.type == "Mesh":
mesh = Blender210.getMesh(object.data)
self.file.write(" Transform {\n")
self.file.write(" children [\n")
self.writeIndexedFaceSet(name, object, mesh, normals = 0)
if mesh.normals:
self.writeIndexedFaceSet(name, object, mesh, normals = 1)
self.file.write(" ]\n")
self.file.write(" }\n")
self.writeEnd()

def writeEnd(self):
self.file.write(" ]\n")
self.file.write("}\n")
self.file.close()
print "... finished"

def writeHeader(self):
self.file.write("#VRML V2.0 utf8\n\n")
self.file.write("Transform {\n")
self.file.write(" children [\n")

def writeIndexedFaceSet(self, name, object, mesh, normals = 0):
newName = string.replace(name, ".", "_")
newName = string.replace(newName, " ", "_")
self.file.write(" DEF %s%s Shape {\n" %
(string.upper(newName), normals))
self.file.write(" appearance Appearance {\n")
self.file.write(" material Material {\n")
self.file.write(" }\n")
self.file.write(" }\n")
self.file.write(" geometry IndexedFaceSet {\n")
# vertices
self.file.write(" coord Coordinate {\n")
self.file.write(" point [\n")
for vertex in mesh.vertices[:-1]:
self.file.write(" %s %s %s,\n" %
(vertex[0], vertex[1], vertex[2]))
vertex = mesh.vertices[-1]
self.file.write(" %s %s %s\n" %
(vertex[0], vertex[1], vertex[2]))
self.file.write(" ]\n")
self.file.write(" }\n")
self.file.write(" coordIndex [\n")
for face in mesh.faces[:-1]:
if face[2] != 0:
if face[3] == 0 and face[4] == normals:
# triangle
self.file.write(" %s, %s, %s" %
(face[0], face[1], face[2]) +
", -1,\n")
elif face[3] != 0 and face[4] == normals:
# quad
self.file.write(" %s, %s, %s, %s" %
(face[0], face[1],
face[2], face[3]) +
", -1,\n")
face = mesh.faces[-1]
if face[2] != 0:
if face[3] == 0 and face[4] == normals:
# triangle
self.file.write(" %s, %s, %s" %
(face[0], face[1], face[2]) +
"\n")
elif face[3] != 0 and face[4] == normals:
# quad
self.file.write(" %s, %s, %s, %s" %
(face[0], face[1],
face[2], face[3]) +
"\n")
self.file.write(" ]\n")
# colors
if mesh.colors:
# vertex colors
print "vertex colors should be used ..."
else:
# face colors
self.file.write(" color Color {\n")
self.file.write(" color [\n")
last = len(object.materials) - 1
for index in xrange(len(object.materials)):
name = object.materials[index]
material = Blender.getMaterial(name)
if index == last:
self.file.write(" %s %s %s\n" %
(material.R, material.G, material.B))
else:
self.file.write(" %s %s %s,\n" %
(material.R, material.G, material.B))
self.file.write(" ]\n")
self.file.write(" }\n")
self.file.write(" colorIndex [\n")
for face in mesh.faces[:-1]:
if face[2] != 0 and face[4] == normals:
self.file.write(" %s,\n" % face[5])
face = mesh.faces[-1]
self.file.write(" %s\n" % face[5])
self.file.write(" ]\n")
self.file.write(" colorPerVertex FALSE\n")
# normals
if normals and mesh.normals:
self.file.write(" normal Normal {\n")
self.file.write(" vector [\n")
for normal in mesh.normals[:-1]:
self.file.write(" %s, %s, %s,\n" %
(normal[0], normal[1], normal[2]))
normal = mesh.normals[-1]
self.file.write(" %s %s %s\n" %
(normal[0], normal[1], normal[2]))
self.file.write(" ]\n")
self.file.write(" }\n")
self.file.write(" }\n")
self.file.write(" }\n")




wrlexport = VrmlExport("str(Blender.Get("Curframe"))+ "test.wrl")
scene = Blender210.getCurrentScene()
wrlexport.export(scene)

#end of script
Reply with quote


sgefant

Posted: Tue Nov 19, 2002 1:14 pm
Joined: 16 Oct 2002
Posts: 49
Quote:
i get this error, what is wrong????

File "<string>", line 140
wrlexport = VrmlExport("str(Blender.Get("Curframe"))+ "test.wrl")
^


The " before str seems to be misplaced. Try removing it.
Reply with quote


dotblend

Posted: Tue Nov 19, 2002 1:24 pm
Joined: 17 Oct 2002
Posts: 72
PYTHON SCRIPT ERROR:
Traceback (most recent call last):
File "wrl2out", line 142, in ?
File "wrl2out", line 22, in export
File "wrl2out", line 43, in writeHeader
ValueError: I/O operation on closed file


this is the result... Sad

tackeld that, now i get

PYTHON SCRIPT ERROR:
Traceback (most recent call last):
File "wrl2out", line 140, in ?
AttributeError: bad request identifier


its driving me nuts!!!!!

all i want is just to get the camera animation in to a vrml2 file :#
Reply with quote


sgefant

Posted: Tue Nov 19, 2002 1:49 pm
Joined: 16 Oct 2002
Posts: 49
hmm.. does replacing
Code:
wrlexport = VrmlExport(str(Blender.Get("Curframe"))+ "test.wrl")

with something like
Code:
name = str(Blender.Get("Curframe"))+"test.wrl"
wrlexport = VrmlExport(name)

help?
Reply with quote


 
Jump to:  
Powered by phpBB © 2001, 2005 phpBB Group