Py3: fix reading/writing from/to OBJ file

This commit is contained in:
wmayer
2019-04-18 12:02:07 +02:00
parent 0607e64140
commit b67b82f4c9

View File

@@ -195,7 +195,7 @@ def export(exportList,filename):
outfile.close()
FreeCAD.Console.PrintMessage(translate("Arch","Successfully written") + " " + decode(filename) + "\n")
if materials:
outfile = pythonopen(filenamemtl,"wb")
outfile = pythonopen(filenamemtl,"w")
outfile.write("# FreeCAD v" + ver[0] + "." + ver[1] + " build" + ver[2] + " Arch module\n")
outfile.write("# http://www.freecadweb.org\n")
kinds = {"AmbientColor":"Ka ","DiffuseColor":"Kd ","SpecularColor":"Ks ","EmissiveColor":"Ke ","Transparency":"d "}
@@ -219,23 +219,23 @@ def export(exportList,filename):
FreeCAD.Console.PrintMessage(translate("Arch","Successfully written") + ' ' + decode(filenamemtl) + "\n")
def decode(name):
"decodes encoded strings"
try:
decodedName = (name.decode("utf8"))
except UnicodeDecodeError:
try:
decodedName = (name.decode("latin1"))
except UnicodeDecodeError:
FreeCAD.Console.PrintError(translate("Arch","Error: Couldn't determine character encoding"))
decodedName = name
return decodedName
#def decode(name):
# "decodes encoded strings"
# try:
# decodedName = (name.decode("utf8"))
# except UnicodeDecodeError:
# try:
# decodedName = (name.decode("latin1"))
# except UnicodeDecodeError:
# FreeCAD.Console.PrintError(translate("Arch","Error: Couldn't determine character encoding"))
# decodedName = name
# return decodedName
def open(filename):
"called when freecad wants to open a file"
docname = (os.path.splitext(os.path.basename(filename))[0]).encode("utf8")
doc = FreeCAD.newDocument(docname)
doc.Label = decode(docname)
docname = (os.path.splitext(os.path.basename(filename))[0])
doc = FreeCAD.newDocument(docname.encode("utf8"))
doc.Label = docname
return insert(filename,doc.Name)
def insert(filename,docname):
@@ -246,7 +246,7 @@ def insert(filename,docname):
doc = FreeCAD.newDocument(docname)
FreeCAD.ActiveDocument = doc
with pythonopen(filename,"rb") as infile:
with pythonopen(filename,"r") as infile:
verts = []
facets = []
activeobject = None
@@ -257,7 +257,7 @@ def insert(filename,docname):
if line[:7] == "mtllib ":
matlib = os.path.join(os.path.dirname(filename),line[7:])
if os.path.exists(matlib):
with pythonopen(matlib,"rb") as matfile:
with pythonopen(matlib,"r") as matfile:
mname = None
color = None
trans = None