I'm trying to write my first Maya plugin and at the very beginning I'm 
starting to have problems...
In my initializePlugin() function I wanted to add some Python script to 
execute when my plugin is loaded and because this script is quite large 
I've put it in separate text file. I added to my C++ code simple function 
to load content of that file and store it in string object:


std::string loadTextFile(const std::string& filePath)
{
    std::ifstream file;
    file.open(filePath.c_str());

    std::string output;
    std::string line;

    if (file.is_open())
    {
        while (file.good())
        {
            getline(file, line);
            output.append(line + "\n");
        }
    }
    else
    {
        std::cerr << "Unable to load file: " << filePath << std::endl;
    }

    return output;
}

And then in initializePlugin() I invoke loadTextFile() and pass my string 
object as an argument using .c_str() method in 
MGlobal::executePythonCommand(). But when I build my .mll file and try to 
load that in Maya I get error message from my loadTextFile() function: *Unable 
to load file*...

My first guess is that the .txt file is in wrong place. For now, just for 
testing purposes, I have simple test.txt file with just one line of code: print 
"Hello!" and as an argument I pass "text.txt" to the loadTextFile() but 
I've tried to put that file in different folders, starting with the most 
obvious: in the same folder where my source files and header files are, in 
the folder where my .mll file is... but none of those works and I get the 
same message.

Does anybody know what may be an issue here? Or maybe there is some another 
way to load Python script into plugin code and then execute it?

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/a02e55ff-8432-47c7-a50e-259014c0d4f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to