[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4372] trunk/py/scripts/addons/ io_import_scene_mhx.py: MHX importer: support for non-ascii names.

Thomas Larsson thomas_larsson_01 at hotmail.com
Thu Mar 14 05:33:10 CET 2013


Revision: 4372
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4372
Author:   thomasl
Date:     2013-03-14 04:33:09 +0000 (Thu, 14 Mar 2013)
Log Message:
-----------
MHX importer: support for non-ascii names.

Modified Paths:
--------------
    trunk/py/scripts/addons/io_import_scene_mhx.py

Modified: trunk/py/scripts/addons/io_import_scene_mhx.py
===================================================================
--- trunk/py/scripts/addons/io_import_scene_mhx.py	2013-03-13 19:21:57 UTC (rev 4371)
+++ trunk/py/scripts/addons/io_import_scene_mhx.py	2013-03-14 04:33:09 UTC (rev 4372)
@@ -39,7 +39,7 @@
 bl_info = {
     'name': 'Import: MakeHuman (.mhx)',
     'author': 'Thomas Larsson',
-    'version': (1, 14, 1),
+    'version': (1, 14, 2),
     "blender": (2, 65, 0),
     'location': "File > Import > MakeHuman (.mhx)",
     'description': 'Import files in the MakeHuman eXchange format (.mhx)',
@@ -52,7 +52,7 @@
 MAJOR_VERSION = 1
 MINOR_VERSION = 14
 FROM_VERSION = 13
-SUB_VERSION = 1
+SUB_VERSION = 2
 
 #
 #
@@ -213,11 +213,12 @@
     theMessage = ""
 
     fileName = os.path.expanduser(filePath)
-    (shortName, ext) = os.path.splitext(fileName)
+    _,ext = os.path.splitext(fileName)
     if ext.lower() != ".mhx":
-        print("Error: Not a mhx file: " + fileName)
+        print("Error: Not a mhx file: %s" % fileName.encode('utf-8', 'strict'))
         return
-    print( "Opening MHX file "+ fileName )
+    print( "Opening MHX file %s " % fileName.encode('utf-8', 'strict') )
+    print("Toggle %x" % toggle)
     time1 = time.clock()
 
     # ignore = False  # UNUSED
@@ -267,7 +268,7 @@
                     tokens[-1][2] = sub
                 level -= 1
             except:
-                print( "Tokenizer error at or before line %d" % lineNo )
+                print( "Tokenizer error at or before line %d.\nThe mhx file has been corrupted.\nTry to export it again from MakeHuman." % lineNo )
                 print( line )
                 stack.pop()
         elif lineSplit[-1] == ';':
@@ -286,7 +287,7 @@
     file.close()
 
     if level != 0:
-        MyError("Tokenizer out of kilter %d" % level)    
+        MyError("Tokenizer error (%d).\nThe mhx file has been corrupted.\nTry to export it again from MakeHuman." % level)    
     scn = clearScene()
     print( "Parsing" )
     parse(tokens)
@@ -296,7 +297,7 @@
             print("Doing %s" % expr)
             exec(expr, glbals, lcals)
         except:
-            msg = "Failed: \n"+expr
+            msg = "Failed: %s\n" % expr
             print( msg )
             nErrors += 1
             #MyError(msg)
@@ -306,7 +307,6 @@
     #bpy.ops.wm.properties_edit(data_path="object", property="MhxRig", value=theArmature["MhxRig"])
         
     time2 = time.clock()
-    print("toggle = %x" % toggle)
     msg = "File %s loaded in %g s" % (fileName, time2-time1)
     if nErrors:
         msg += " but there where %d errors. " % (nErrors)
@@ -370,8 +370,7 @@
 def parse(tokens):
     global MHX249, ifResult, theScale, defaultScale, One
     
-    for (key, val, sub) in tokens:    
-        print("Parse %s" % key)
+    for (key, val, sub) in tokens: 
         data = None
         if key == 'MHX':
             checkMhxVersion(int(val[0]), int(val[1]))
@@ -454,7 +453,6 @@
             if ob:
                 bpy.context.scene.objects.active = ob
                 mat = ob.data.materials[int(val[2])]
-                print("matanim", ob, mat)
                 parseAnimationData(mat, val, sub)
         elif key == 'ShapeKeys':
             try:
@@ -467,10 +465,6 @@
         else:
             data = parseDefaultType(key, val, sub)                
 
-        if data and key != 'Mesh':
-            print( data )
-    return
-
 #
 #    parseDefaultType(typ, args, tokens):
 #
@@ -481,20 +475,15 @@
     name = args[0]
     data = None
     expr = "bpy.data.%s.new('%s')" % (Plural[typ], name)
-    # print(expr)
     data = eval(expr)
-    # print("  ok", data)
 
     bpyType = typ.capitalize()
-    print(bpyType, name, data)
     loadedData[bpyType][name] = data
     if data is None:
         return None
 
     for (key, val, sub) in tokens:
-        #print("%s %s" % (key, val))
         defaultKey(key, val, sub, 'data', [], globals(), locals())
-    print("Done ", data)
     return data
     
 #
@@ -597,7 +586,6 @@
         expr = "ob.%s]" % (words[0])
         cwords = words[1].split('"')
         channel = cwords[1]
-    # print(expr, channel, index)
     return (expr, channel)
 
 def parseActionFCurve(act, ob, args, tokens):
@@ -647,7 +635,6 @@
 def parseAnimationData(rna, args, tokens):
     if not eval(args[1]):
         return
-    print("Parse Animation data")
     if rna.animation_data is None:    
         rna.animation_data_create()
     adata = rna.animation_data
@@ -656,7 +643,6 @@
             fcu = parseAnimDataFCurve(adata, rna, val, sub)            
         else:
             defaultKey(key, val, sub, 'adata', [], globals(), locals())
-    print(adata)
     return adata
 
 def parseAnimDataFCurve(adata, rna, args, tokens):
@@ -692,7 +678,6 @@
         expr = "rna." + words[0] + ']'
         pwords = words[1].split('"')
         prop = pwords[1]
-        #print("prop", expr, prop)
         bone = eval(expr)
         return None
     else:
@@ -703,12 +688,9 @@
             expr += "." + words[n]
         expr += ".driver_add('%s', index)" % channel
     
-    #print("expr", rna, expr)
     fcu = eval(expr)
     drv = fcu.driver
-    #print("   Driver type", drv, args[0])
     drv.type = args[0]
-    #print("   ->", drv.type)
     for (key, val, sub) in tokens:
         if key == 'DriverVariable':
             var = parseDriverVariable(drv, rna, val, sub)
@@ -719,9 +701,7 @@
 def parseDriverVariable(drv, rna, args, tokens):
     var = drv.variables.new()
     var.name = args[0]
-    #print("   Var type", var, args[1])
     var.type = args[1]
-    #print("   ->", var.type)
     nTarget = 0
     for (key, val, sub) in tokens:
         if key == 'Target':
@@ -752,7 +732,6 @@
     dtype = args[1].capitalize()
     dtype = 'Object'
     targ.id = loadedData[dtype][name]
-    #print("    ->", targ.id)
     for (key, val, sub) in tokens:
         if key == 'data_path':
             words = val[0].split('"')
@@ -932,7 +911,7 @@
     path1 = os.path.expanduser(filepath)
     file1 = os.path.realpath(path1)
     if os.path.isfile(file1):
-        print( "Found file "+file1 )
+        print( "Found file %s." % file1.encode('utf-8','strict') )
         try:
             img = bpy.data.images.load(file1)
             return img
@@ -940,7 +919,7 @@
             print( "Cannot read image" )
             return None
     else:
-        print( "No file "+file1 )
+        print( "No such file: %s" % file1.encode('utf-8','strict') )
         return None
 
 
@@ -952,13 +931,13 @@
     file1 = os.path.realpath(path1)
     (path, filename) = os.path.split(file1)
     (name, ext) = os.path.splitext(filename)
-    print( "Loading ", filepath, " = ", filename )
+    print( "Loading %s = %s" % (filepath.encode('utf-8','strict'), filename.encode('utf-8','strict')) )
 
     # img = doLoadImage(texDir+"/"+name+".png")
     # if img:
     #    return img
 
-    img = doLoadImage(texDir+"/"+filename)
+    img = doLoadImage(os.path.join(texDir, filename))
     if img:
         return img
 
@@ -966,7 +945,7 @@
     # if img:
     #    return img
 
-    img = doLoadImage(path+"/"+filename)
+    img = doLoadImage(os.path.join(path, filename))
     if img:
         return img
 
@@ -977,7 +956,7 @@
     TexDir = Draw.PupStrInput("TexDir? ", path, 100)
 
     texDir = os.path.expanduser(TexDir)
-    img =  doLoadImage(texDir+"/"+name+".png")
+    img =  doLoadImage(os.path.join(texDir, name+".png"))
     if img:
         return img
 
@@ -1035,9 +1014,7 @@
         ob = None
 
     if ob is None:
-        print("Create", name, data, datName)
         ob = createObject(typ, name, data, datName)
-        print("created", ob)
         linkObject(ob, data)
 
     for (key, val, sub) in tokens:
@@ -1056,7 +1033,6 @@
             
     if bpy.context.object == ob:
         if ob.type == 'MESH':
-            print("Smooth shade", ob)
             bpy.ops.object.shade_smooth()
     else:
         print("Context", ob, bpy.context.object, bpy.context.scene.objects.active)
@@ -1074,7 +1050,6 @@
     #print("Data", data, ob.data)
     if data and ob.data is None:
         ob.data = data
-        print("Data linked", ob, ob.data)
     scn = bpy.context.scene
     scn.objects.link(ob)
     scn.objects.active = ob
@@ -1244,10 +1219,8 @@
         try:
             me.polygons
             BMeshAware = True
-            print("Using BMesh")
         except:
             BMeshAware = False
-            print("Not using BMesh")
         
     mats = []
     nuvlayers = 0
@@ -1281,7 +1254,6 @@
                 parseFaces2BMesh(sub, me)
             else:
                 parseFaces2NoBMesh(sub, me)
-    print(me)
     return me
 
 #
@@ -1504,6 +1476,7 @@
     else:
         return (toggle & T_Face)
 
+
 def parseShapeKeys(ob, me, args, tokens):
     for (key, val, sub) in tokens:
         if key == 'ShapeKey':
@@ -1521,8 +1494,6 @@
             prop = "Mhv" + name
             parseUnits(prop, ob, sub)            
     ob.active_shape_key_index = 0
-    print("Shapekeys parsed")
-    return
 
             
 def parseUnits(prop, ob, sub):
@@ -1552,6 +1523,7 @@
         MyError("ShapeKey L/R %s" % lr)
     return
 
+
 def addShapeKey(ob, name, vgroup, tokens):
     skey = ob.shape_key_add(name=name, from_mix=False)
     if name != 'Basis':
@@ -1641,13 +1613,6 @@
         #    pass
         elif key == 'hide' and val[0] == 'True':
             name = bone.name
-            '''
-            #bpy.ops.object.mode_set(mode='OBJECT')
-            pbone = amt.bones[name]
-            pbone.hide = True
-            print("Hide", pbone, pbone.hide)
-            #bpy.ops.object.mode_set(mode='EDIT')            
-            '''
         else:
             defaultKey(key, val,  sub, "bone", [], globals(), locals())
     return bone
@@ -1675,9 +1640,7 @@
             prop = val[1]
             value = eval(val[2])
             pb = pbones[bone]
-            print("Setting", pb, prop, val)
             pb[prop] = value
-            print("Prop set", pb[prop])
         else:
             defaultKey(key, val,  sub, "ob.pose", [], globals(), locals())
     bpy.ops.object.mode_set(mode='OBJECT')
@@ -2150,6 +2113,8 @@
 
 def propNames(string):
     global alpha7
+    #string = string.encode('utf-8', 'strict')
+    
     # Alpha 7 compatibility
     if string[0:2] == "&_":
         string = "Mhf"+string[2:]
@@ -2160,15 +2125,16 @@
     elif string[0] == "*":
         string = "Mhs"+string[1:]
         alpha7 = True
-    elif string.startswith("Hide"):

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list