Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- import sys
- import tempfile
- from telnetlib import Telnet
- from time import sleep
- import os
- bl_info = {
- "name": "Send to Maya",
- "author": "Sven Akelian - BlenderLounge",
- "blender": (2, 7, 0),
- "location": "VIEW3D -> UI panel",
- "description": "Send selected Objects to Maya",
- "warning": "Still in dev.",
- "category": "Import-Export"
- }
- # In maya you first need to open the port using this command:
- #
- host = 'localhost'
- port = 7002
- def export_defaults(file):
- bpy.ops.wm.alembic_export(
- filepath=file,
- # check_existing=0,
- selected=1,
- normals=1,
- uvs=1,
- # vcolors=1,
- global_scale=1,
- )
- class OBJECT_OT_sendMaya(bpy.types.Operator):
- bl_idname = 'object.send_to_maya'
- bl_label = 'Send'
- bl_options = {'REGISTER'}
- def invoke(self, context, event):
- context.window_manager.invoke_props_dialog(self)
- return {'RUNNING_MODAL'}
- def execute(self, context):
- # Set temporary file and export
- file = tempfile.NamedTemporaryFile(suffix=".abc",delete=False)
- file.close()
- export_defaults(file.name)
- # TODO: Here find an appropriate/pythonic way to check the state of the ABC File
- checkfileStatus(file.name)
- try:
- c = Telnet(host, port, timeout=3)
- message = "import pymel.core as pm;pm.importFile('" + file.name + "')"
- c.write(message.encode("utf-8"))
- except Exception:
- e = sys.exc_info()[1]
- err = str(e)
- msg = "Failed to communicate with Maya (%(host)s:%(port)s)):\n%(err)s" % locals()
- raise
- else:
- sleep(.1)
- finally:
- try:
- if c is not None:
- c.close()
- except:
- print("ERROR")
- return {'FINISHED'}
- class VIEW3D_PT_sendMaya(bpy.types.Panel):
- bl_idname = "OBJECT_PT_send_to_maya"
- bl_label = "Send to Maya"
- bl_space_type = "VIEW_3D"
- bl_region_type = "UI"
- def draw(self, context):
- self.layout.row().operator('object.send_to_maya')
- def checkfileStatus(file):
- """
- Blocking function.
- Hacky way to get the filestatus from Blender's abc save.
- Checking the file size over time, break when there is no more difference...
- """
- while True:
- fileInit = os.stat(file)
- sleep(1)
- fileNew = os.stat(file)
- difference = fileNew.st_size - fileInit.st_size
- if difference == 0:
- break
- else:
- sleep(5)
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement