I've got an automated process that produces 100's of blend files for use in Unity. I need to change each of these files to fix some things. I've got other scripts that are ugly but get the job done, like renaming materials and object names and turn off auto smooth and double sided. Now I would like to generate a UV map and scale it to a real world size (I'm trying to use the Magic-UV add-on.) I've made this script:
import bpy def ApplyWorldScaleUV(): scene = bpy.context.scene scene.layers = [True] * 20 # Show all layers for obj in scene.objects: if obj.type == 'MESH': print(">>>> START >>>> ApplyWorldScaleUV obj name: %s" %obj.name) scene.objects.active = obj obj.select = True bpy.ops.object.mode_set(mode='EDIT') bpy.ops.mesh.select_all(action='SELECT') bpy.ops.uv.smart_project(angle_limit=66.0, island_margin=0.001, user_area_weight=0.0, stretch_to_bounds=False) bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.mesh.primitive_cube_add() bpy.ops.uv.cube_project() bpy.ops.uv.muv_wsuv_measure() bpy.ops.mesh.delete(type='FACE') bpy.ops.mesh.select_all(action='SELECT') bpy.ops.uv.muv_wsuv_apply() bpy.ops.object.mode_set(mode='OBJECT') print(">>>> END >>>> ") ApplyWorldScaleUV()
If I open a belnder file, open this script in the text editor and run it, it works. But I've got 100's of files, so I want to automate it. When I try to run it from a command line (Windows 7 FYI) using:
blender.exe example.blend -P C:\temp\realWorldUV.py
I get the error:
RuntimeError: Error: Traceback (most recent call last): File "C:\Program Files\Blender Foundation\Blender\2.78\scripts\addons\uv_magic_uv\muv_wsuv_ops.py", line 127, in execute orig_area = bpy.context.area.type AttributeError: 'NoneType' object has no attribute 'type'
I'm quite confused by all the context issues, and I've been working on this for over a day.
Is there a way I can get this to work?