imbedding a python plugin c++ mll?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 01 January 2013   #1
imbedding a python plugin c++ mll?

I have a plugin that requires a command to make the necessary connections within Maya. Python is so much easier than C++ to make dg connections. Is it possible for me to write the command in python and imbed it in the c++/mll code somehow?
 
Old 01 January 2013   #2
Are you just looking to execute Python commands from a C++ plugin? If so you can pass the Python code through the MGlobal::executePythonCommand method inside your plugin.
 
Old 01 January 2013   #3
http://download.autodesk.com/us/may...afa28562db9 9f
 
Old 01 January 2013   #4


Thanks zoharl, would the python command be a separate file or is there a way to compile the python code along with the c++ code within one VS solution? The reason I want this is so that when the user loads the plugin, all the commands necessary to use the plugin are loaded as well. In a straight forward c++ plugin, I would compile the commands along with the dependency nodes. I'm not sure how to combine Python code.
 
Old 01 January 2013   #5
It executes a python command as if you executed it in the script editor. Which means that if you call external scripts, they should be in the path like they are required when calling them within maya. If you don't want to use external scripts, the simplest solution would be to embed a python script as a long c++ string. I think it should be quite straight forward to write a script that takes a python script and convert it to a C++ const char *. It should involve putting each line of the python script in quotation marks, escaping special characters, and connecting all these strings with + and '\n'.
Another option might be to embed the python script as a string resource (resource: dialog, icon, etc...).
 
Old 01 January 2013   #6
Other ideas:

http://stackoverflow.com/questions/...-in-a-c-program
http://stackoverflow.com/questions/...ows-application
 
Old 01 January 2013   #7
Originally Posted by zoharl: It executes a python command as if you executed it in the script editor. Which means that if you call external scripts, they should be in the path like they are required when calling them within maya. If you don't want to use external scripts, the simplest solution would be to embed a python script as a long c++ string. I think it should be quite straight forward to write a script that takes a python script and convert it to a C++ const char *. It should involve putting each line of the python script in quotation marks, escaping special characters, and connecting all these strings with + and '\n'.
Another option might be to embed the python script as a string resource (resource: dialog, icon, etc...).


yup, I was afraid of that. Thanks zoharl
 
Old 01 January 2013   #8
Another option for including external resources:

If you build as a Qt project (Maya 2011+) , you can include the python file in the .qrc (resource) file. These files are compiled into the executable and can be opened and read similar to a file that exists on disk (by using the resource path).

e.g.
QFile file(":/python/test_file.py");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
    Logger::displayError("Failed to open python file");
}
QByteArray data = file.readAll();
MString command = MQtUtil::toMString(QString(data));
MGlobal::executePythonCommand(command);

There are several benefits to this approach, most notably, it is cross-platform. It also allows you to write and maintain the python code in a more suitable python editor. For larger chunks of code, it can become a real pain trying to hard code python directly in C++ (managing the newlines, tab spacing, etc...).

The python file can read and executed when the plugin is loaded, making all of the functions available to the plugin (through executePythonCommand), and the user.
 
Old 01 January 2013   #9
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:45 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.