Skip to content

Instantly share code, notes, and snippets.

@yamahigashi
Last active December 16, 2015 12:09
Show Gist options
  • Save yamahigashi/5432595 to your computer and use it in GitHub Desktop.
Save yamahigashi/5432595 to your computer and use it in GitHub Desktop.
maya plugin, send selected to softimage via TCPServer_For_Softimage (https://github.com/KelSolaar/TCPServer_For_Softimage)
# locate this file into maya plug-ins/scripted folder.
# enable Plug-in Manager
# prerequire fbxmaya.mll
import sys
import os
import socket
import maya.mel as mel
import maya.OpenMayaMPx
###############################################################################
SI_TCP_SERVER_PORT = 12288
kPluginCmdName = "SendSelectedToSoftimage"
###############################################################################
class SendSelectedToSoftimage(maya.OpenMayaMPx.MPxCommand):
def __init__(self):
maya.OpenMayaMPx.MPxCommand.__init__(self)
def doIt(self, args):
tmp_folder = os.path.join(os.environ["TMP"], "codebridge")
fbx_path = tmp_folder + "/maya_to_xsi_tmp"
if not os.path.exists(tmp_folder):
os.mkdir(tmp_folder)
mel.eval('select -hi')
mel.eval('FBXExport -f "%s" -s;' % fbx_path.replace("\\", "/"))
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.connect(("127.0.0.1", SI_TCP_SERVER_PORT))
conn.send("Python|Application.FBXImport(\""+fbx_path+".fbx\")")
conn.close()
def creator():
return maya.OpenMayaMPx.asMPxPtr(SendSelectedToSoftimage())
def initializePlugin(mObject):
mPlugin = maya.OpenMayaMPx.MFnPlugin(mObject)
try:
mPlugin.registerCommand(kPluginCmdName, creator)
except:
sys.stderr.write('Failed load plugin : %s' % kPluginCmdName)
raise
def uninitializePlugin(mObject):
mPlugin = maya.OpenMayaMPx.MFnPlugin(mObject)
try:
mPlugin.deregisterCommand(kPluginCmdName)
except:
sys.stderr.write('Failed unload plugin : %s' % kPluginCmdName)
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment