PDA

View Full Version : Load Compiled Python (*.pyc) Plug-in


meljunky
03-06-2008, 11:04 PM
Wondering if it is possible to load a compiled Python plug-in. Notice that if you load a Python script (.py) a compiled version is created (.pyc). If you load the pyc file I get the following error. Also, tried the Python command to compile code.

// Error: file: C:/Program Files/Autodesk/Maya8.5/scripts/others/pluginWin.mel line 638: Plug-in, "D:/Documents and Settings/Admin/My Documents/maya/8.5/plug-ins/samplePlugin.pyc.mll", was not found on MAYA_PLUG_IN_PATH. //
// Warning: Could not load C:/Documents and Settings/Admin/My Documents/maya/8.5/plug-ins/samplePlugin.pyc as a plug-in //
// Result: 0 //


As you can see in the error a ".mll" was added to the end of the file's name.

The reason why I am asking...
If you open up the Plug-in Manager and click on the Browse button, the following filter are placed on the search: *.mll, *.so, *.py, *.pyc

The pyc extension is listed as one of the file types available.

Has anybody have any luck loading a compiled Python plug-in or did Maya make a mistake?

-brian
www.meljunky.com (http://www.meljunky.com)

kjaft
03-07-2008, 07:32 AM
I didn't try myself. I just noticed that with Graph Editor Redux, a Grpah Editor extension available on highend3d, the initialize/uninitializePlugin routines are in a .py while the rest is in .pyc files.

meljunky
03-12-2008, 05:04 AM
After some testing with the two functions you mentioned: initialize/uninitializePlugin in an uncompiled python script (.py), I got it to work.

for those who need to know...
File: sampleFile.py

#import normal modules for python and maya
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
import sys
import sampleCompiledFile as scf
# where sampleCompiledFile is the compiled python file (*.pyc)

# intialize script plugins
def initializePlugin(obj):
plugin = OpenMayaMPx.MFnPlugin(obj, "meljunky", "1.0", "Any")
try:
plugin.registerCommand( scf.kPluginCmdName, scf.cmdCreator, scf.syntaxCreator)
sys.stderr.write( "Register command complete: %s\n" % scf.kPluginCmdName )
except:
sys.stderr.write("Failed to register command %s \n" % scf.kPluginCmdName)
raise


#unitialize script plugins
def uninitializePlugin(obj):
mplugin = OpenMayaMPx.MFnPlugin(obj)
try:
mplugin.deregisterCommand(scf.kPluginCmdName)
except:
sys.stderr.write("Failed to unregister command %s\n" % scf.kPluginCmdName)
raise


So when sampleFile.py is loaded as a plugin the initialize/uninitializePlugin functions will reference the compiled file sampleCompiledFile.pyc because of the line:
import sampleCompiledFile as scf

I have trying out many different methods and placing the pyc and py files in multiple locations I wondered if python imported the compiled python module versus the uncompiled file with the same name.

To check the location and file is correct I used:
import sampleCompiledFile as scf
scf.__file__
#Results:
# Result: H:/python code\sampleCompiledFile.pyc #

The compiled file will contain:
import modules commands, kPluginCmdName, custom flags, scriptedCommand, cmdCreator, syntaxCreator, custom functions, classes ,etc

You names may be different as I am referencing Maya's sample API commands.


Thanks kjaft for pointing me on the right direction!

-brian
www.meljunky.com (http://www.meljunky.com)

CGTalk Moderation
03-12-2008, 05:04 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.