Send to Maya

Hi,

I wrote this script snippet a while ago to speed up my workflow between Blender and Maya. It essentially sends all selected objects to Maya via OBJ export.

I came back to it recently and thought about expanding it and maybe offering the export format to be FBX instead of OBJ.

So yeah, I would just like to know what you think of the idea and what you would expect from such a script.

bl_info = {
  "name": "Send to Maya",
  "author": "Felix Schlitter",
  "blender": (2, 5, 9),
  "api": 35622,
  "location": "VIEW3D -> UI panel",
  "description": "Send selected Objects to Maya",
  "warning": "Only tested with Win7 and Maya2011.",
  "category": "Import-Export"}

import bpy

def export_defaults(file, use_modifiers):
  bpy.ops.export_scene.obj(
            filepath=file,
            check_existing=0,
            filter_glob="*.obj;*.mtl",
            use_selection=1,
            use_all_scenes=0,
            use_animation=0,
            use_apply_modifiers=use_modifiers,
            #use_rotate_x90=1,
            use_edges=1,
            use_normals=1,
            use_hq_normals=1,
            use_uvs=1,
            use_materials=0,
            use_triangles=0,
            use_vertex_groups=0,
            use_nurbs=1,
            use_blen_objects=0,
            group_by_object=1,
            group_by_material=0,
            keep_vertex_order=1,
            global_scale=1,
            axis_forward='-Z',
            axis_up='Y',
            path_mode='AUTO')

class OBJECT_OT_sendMaya(bpy.types.Operator):
  bl_idname = 'object.send_to_maya'
  bl_label = 'Send to Maya'
  bl_options = {'REGISTER'}
  use_modifiers = bpy.props.BoolProperty(
                    name = "Apply modifiers",
                    description = "",
                    default = True
                  )
  
  def invoke(self, context, event):
    context.window_manager.invoke_props_dialog(self)
    return {'RUNNING_MODAL'}
    
  def execute(self, context):
    import socket
    import tempfile
    host = 'localhost'
    port = 50007
    maya = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    try:
      # Connect to Maya Command Port
      maya.connect((host,port))
      
      # Set temporary file and export
      file = (tempfile.gettempdir()+'.obj').replace("\\","/")
      export_defaults(file, self.use_modifiers)
 
      # Prepare MEL script to be run from Maya
      message = 'file -import -type "OBJ" -ra true -options "mo=1"  -pr -loadReferenceDepth "all" "'+file+'";'
      maya.send(message.encode())

    except socket.error as err:
      self.report({'ERROR'},message='Could not connect to Maya. Make sure Maya is running. Check console for more information.')
      print(err)
    maya.close()
    
    return {'FINISHED'}
    
class VIEW3D_PT_sendMaya(bpy.types.Panel):
  bl_idname = "OBJECT_PT_send_to_maya"
  bl_label = "Export OBJ"
  bl_space_type = "VIEW_3D"
  bl_region_type = "UI"
  
  def draw(self, context):
    self.layout.row().operator('object.send_to_maya')

def register():
  bpy.utils.register_class(OBJECT_OT_sendMaya)
  bpy.utils.register_class(VIEW3D_PT_sendMaya)
  
def unregister():
  bpy.utils.unregister_class(OBJECT_OT_sendMaya)
  bpy.utils.unregister_class(VIEW3D_PT_sendMaya)

Cheers,
Felix