Cool. Let us know if you end up solving it!
On Mon, Nov 23, 2015 at 11:41 AM Peter Makal <[email protected]> wrote:
> I will definitely try this.
> Thanks Justin!
>
>
> On Sunday, November 22, 2015 at 9:12:00 PM UTC+1, Justin Israel wrote:
>
>> You may be able to simplify this whole thing by either using
>> MGlobal::executePythonCOmmand("execfile <myScript.py>") or using the module
>> system to bundle your extra files and then be able to query the module path
>> (getModulePath).
>>
>> As a side note, I think you could shorten your process for reading a file
>> to just reading it into a buffer, instead of reading each line, and
>> building up strings:
>>
>> std::ifstream ifs("myfile.txt");
>> std::stringstream stream;
>> stream << ifs.rdbuf();return stream.str();
>>
>>
>>
>> Justin
>>
>>
>> On Mon, Nov 23, 2015 at 2:42 AM Peter Makal <[email protected]> wrote:
>>
>>> Ok, I finally manage to read Python code from my file. I checked current
>>> working directory in my plugin code and it happens to be Maya installation
>>> folder which is not ideal but for now it will suffice.
>>> I guess I should use MEL getenv MAYA_PLUG_IN_PATH command and extract
>>> some absolute path where my plugin will be installed.
>>>
>>> On Sunday, November 22, 2015 at 12:15:29 PM UTC+1, Peter Makal wrote:
>>>>
>>>> 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/c2a85735-a2e3-48a7-9cf9-54368ddb8e30%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/c2a85735-a2e3-48a7-9cf9-54368ddb8e30%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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/fe23dadb-b36a-4773-bbbd-352a4bb8cbb7%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/fe23dadb-b36a-4773-bbbd-352a4bb8cbb7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAPGFgA2j6KLLZ5PEPJWKP6oiU1bABXmsqB9R4w%2Bc5XV-8rLTBQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.