Oh, i see. That's new to me :D
However, if you call a sequence of command like this, you will not get any
return value, right?

On Sat, Jun 6, 2015 at 3:13 PM, Justin Israel <[email protected]>
wrote:

> The commandPort has its own local scope which is not the same as what you
> are defining in the Script Editor (if that is what you meant by creating a
> new function in Maya. You can check this by creating functions or variables
> in the Script Editor and then doing this in the Script Editor:
>
> import __main__print __main__.__dict__.keys()
>
> You should see all the symbols that are defined in the global namespace,
> which is what the tabs in the script editor see. But when you run commands
> in the commandPort, they are in a different scope. But you can access the
> main namespace if you want:
>
> import __main__; __main__.printOut()
>
> And creating symbols in the global space:
>
> import __main__; __main__.foo = "foo"
>
> For some more information about using scopes, you could look at the
> MayaSublime plugin to see how I run commands:
> https://github.com/justinfx/MayaSublime/blob/master/MayaSublime.py#L38
>
> I actually save a special namespace that gets reused for every call. It is
> there so as not to pollute Maya’s global namespace, but persist the state
> of what you are doing from Sublime.
>
> Justin
>
> On Sat, Jun 6, 2015 at 7:53 PM Tuan Nguyen [email protected]
> <http://mailto:[email protected]> wrote:
>
> Oh sorry, Here how i call it
>> QByteArray array = (QString("printOut()").toStdString().c_str());
>>
>>     if(m_socket->waitForConnected(5000)) {
>>
>>         m_socket->write(array);
>>
>>         m_socket->waitForBytesWritten(1000);
>>
>>         m_socket->waitForReadyRead(5000);
>>
>>
>>         qDebug() << "Reading: " << m_socket->bytesAvailable();
>>
>>         qDebug() << m_socket->readAll();
>>
>>     }
>>
>>
>>
>> On Sat, Jun 6, 2015 at 2:49 PM, Tuan Nguyen <[email protected]>
>> wrote:
>>
>>> After open commandPort in terminal
>>> maya.exe -command "commandPort -name \":7002\" -sourceType \"python\""
>>>
>>> I create a QTcpSocket and connect it to maya
>>> QTcpSocket m_socket = new QTcpSocket(this);
>>> m_socket->connectToHost("127.0.0.1", 7002);
>>>
>>> I try simple command like cmds.polySphere() and it works fine. After
>>> that, i create a new function in Maya like:
>>> def printOut() :
>>>    print "Hello World"
>>>    return "Hello World"
>>>
>>> using the same method like above to connect to Maya, but it told me that
>>> name "printOut" is not define
>>>
>>>
>>> On Sat, Jun 6, 2015 at 2:36 PM, Justin Israel <[email protected]>
>>> wrote:
>>>
>>>> Its probably because the function you want to call isn't defined in the
>>>> scope that is used in the commandPort call. Where is this user function
>>>> defined and how are you calling it?
>>>>
>>>> On Sat, 6 Jun 2015 6:41 PM Tuan Nguyen <[email protected]> wrote:
>>>>
>>>>> Sorry for dig this up.
>>>>> Its funny that i can't call user's python function from python
>>>>> commandPort. It keep telling me that function is not available.
>>>>> How should i deal with it?
>>>>>
>>>>> On Fri, May 8, 2015 at 2:39 AM, Justin Israel <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> That's pretty useful. Strange it wasn't documented.
>>>>>>
>>>>>> On Thu, 7 May 2015 11:33 PM Tuan Nguyen <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> Hidden treasure huh? Now Autodesk want to play it RPG style :D
>>>>>>> Thank for your help Anthony
>>>>>>>
>>>>>>> On Thu, May 7, 2015 at 6:23 PM, Anthony Tan <
>>>>>>> [email protected]> wrote:
>>>>>>>
>>>>>>>>  It may not have made it into the docs (okay, it clearly hasn't)
>>>>>>>> but there's a listPorts flag for the command that might be of use?
>>>>>>>>
>>>>>>>> import maya.cmds as mc
>>>>>>>> mc.commandPort(name="fish:65499")
>>>>>>>> print mc.commandPort(listPorts=1,q=True)
>>>>>>>> [u'mayaCommand', u'fish:65499', u'commandportDefault']
>>>>>>>>
>>>>>>>> (and the only reason I know that exists is because my first
>>>>>>>> reaction was to run help against the MEL - sometimes the online help 
>>>>>>>> takes
>>>>>>>> too dang long to load :P)
>>>>>>>>
>>>>>>>> help commandPort
>>>>>>>> // Result:
>>>>>>>>
>>>>>>>> Synopsis: commandPort [flags] [String]
>>>>>>>> Flags:
>>>>>>>>    -q -query
>>>>>>>>   -bs -bufferSize         Int
>>>>>>>>   -cl -close
>>>>>>>>   -eo -echoOutput
>>>>>>>>   -lp -listPorts
>>>>>>>>    -n -name               String
>>>>>>>>   -nr -noreturn
>>>>>>>>   -po -pickleOutput
>>>>>>>>  -pre -prefix             String
>>>>>>>>  -rnc -returnNumCommands
>>>>>>>>  -stp -sourceType         String
>>>>>>>>   -sw -securityWarning
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, May 7, 2015, at 09:05 PM, Tuan Nguyen wrote:
>>>>>>>>
>>>>>>>> Hi Justin
>>>>>>>> Thank for extra information, but how can you know which one message
>>>>>>>> will be send to  in case users open multi-application's instance at the
>>>>>>>> same time?
>>>>>>>>
>>>>>>>> commandPort doesn't allow us to query port's name but only checking
>>>>>>>> it. I can do a for loop, but somehow, i feel uneasy with that way :)
>>>>>>>>
>>>>>>>> On Thu, May 7, 2015 at 5:50 PM, Justin Israel <
>>>>>>>> [email protected]> wrote:
>>>>>>>>
>>>>>>>> Are you looking to find out this information from within the Maya
>>>>>>>> process, or external to the Maya process?
>>>>>>>>
>>>>>>>> Maya allows you to open multiple command ports, so there isn't
>>>>>>>> necessarily just one. The docs show how you can query is a specific 
>>>>>>>> named
>>>>>>>> port is open:
>>>>>>>>
>>>>>>>> http://download.autodesk.com/global/docs/maya2014/en_us/CommandsPython/commandPort.html
>>>>>>>>
>>>>>>>> If you are looking to find out which ports are open, from outside
>>>>>>>> of Maya, then that is going to depend on which platform you are 
>>>>>>>> running. On
>>>>>>>> OSX/Linux you could use the "lsof" command to check what a given 
>>>>>>>> process is
>>>>>>>> listening on:
>>>>>>>>
>>>>>>>> # list the tcp sockets that are listening from a Maya pid
>>>>>>>> $ lsof -i 4 -a -p <pid> | grep LISTEN
>>>>>>>>
>>>>>>>> # list the unix domain sockets that are open from a Maya pid
>>>>>>>> $ lsof -U -a -p <pid>
>>>>>>>>
>>>>>>>>
>>>>>>>> Justin
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Thu, 7 May 2015 10:01 PM illunara <[email protected]> wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Hi everybody
>>>>>>>> I wonder if we can get port or port's name using for commandPort of
>>>>>>>> current maya's instance?. I had been searching on google for a while 
>>>>>>>> but no
>>>>>>>> luck
>>>>>>>> Thanks
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>>  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/12d63e01-519c-4007-bb9e-5c701bd547aa%40googlegroups.com
>>>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/12d63e01-519c-4007-bb9e-5c701bd547aa%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 a topic in
>>>>>>>> the Google Groups "Python Programming for Autodesk Maya" group.
>>>>>>>>  To unsubscribe from this topic, visit
>>>>>>>> https://groups.google.com/d/topic/python_inside_maya/ct5I0Q4Vs94/unsubscribe
>>>>>>>> .
>>>>>>>>  To unsubscribe from this group and all its topics, send an email
>>>>>>>> to [email protected].
>>>>>>>>  To view this discussion on the web visit
>>>>>>>> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1qHuLvGK7V6SAmjXe_NwC65O9q2B0RpxML-pgNd-Z-RA%40mail.gmail.com
>>>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1qHuLvGK7V6SAmjXe_NwC65O9q2B0RpxML-pgNd-Z-RA%40mail.gmail.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/CAMCvD%2BGCZEK-P_ziJmQM%3D_NUbiXyTQA-M7m17_wSsAo4a%3DC7dw%40mail.gmail.com
>>>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BGCZEK-P_ziJmQM%3D_NUbiXyTQA-M7m17_wSsAo4a%3DC7dw%40mail.gmail.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 a topic in
>>>>>>>> the Google Groups "Python Programming for Autodesk Maya" group.
>>>>>>>> To unsubscribe from this topic, visit
>>>>>>>> https://groups.google.com/d/topic/python_inside_maya/ct5I0Q4Vs94/unsubscribe
>>>>>>>> .
>>>>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>>>>> [email protected].
>>>>>>>>
>>>>>>> To view this discussion on the web visit
>>>>>>>> https://groups.google.com/d/msgid/python_inside_maya/1430997792.224981.263905553.1EF079A3%40webmail.messagingengine.com
>>>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/1430997792.224981.263905553.1EF079A3%40webmail.messagingengine.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/CAMCvD%2BHKnWOWtzVwGLKioSbq6XdXY9NMJ%3DiP9gnHc_ukdup42Q%40mail.gmail.com
>>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BHKnWOWtzVwGLKioSbq6XdXY9NMJ%3DiP9gnHc_ukdup42Q%40mail.gmail.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 a topic in
>>>>>> the Google Groups "Python Programming for Autodesk Maya" group.
>>>>>> To unsubscribe from this topic, visit
>>>>>> https://groups.google.com/d/topic/python_inside_maya/ct5I0Q4Vs94/unsubscribe
>>>>>> .
>>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>>> [email protected].
>>>>>>
>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3h%3D3rM_v-qk2ivejR-m7DXXBTqb0LjLQJWHEhCsueTyg%40mail.gmail.com
>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3h%3D3rM_v-qk2ivejR-m7DXXBTqb0LjLQJWHEhCsueTyg%40mail.gmail.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/CAMCvD%2BG_fOTAbk15gkLUMZJowsO%3DCTgdxkECXheAD8T3uy_3kQ%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BG_fOTAbk15gkLUMZJowsO%3DCTgdxkECXheAD8T3uy_3kQ%40mail.gmail.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 a topic in the
>>>> Google Groups "Python Programming for Autodesk Maya" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/python_inside_maya/ct5I0Q4Vs94/unsubscribe
>>>> .
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0xgQHLbCvLcnXU%2BfwLiPAVrUzb_2WahERgeqge7cnbmw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0xgQHLbCvLcnXU%2BfwLiPAVrUzb_2WahERgeqge7cnbmw%40mail.gmail.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/CAMCvD%2BHzb6H2erEjZ8%3DAqr-F-wrCBoTgJAaKiz72hJGr_d3nQA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAMCvD%2BHzb6H2erEjZ8%3DAqr-F-wrCBoTgJAaKiz72hJGr_d3nQA%40mail.gmail.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 a topic in the
> Google Groups "Python Programming for Autodesk Maya" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python_inside_maya/ct5I0Q4Vs94/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3FfpnN7jVV7VGi1MD%3D_xJEw04eCBzZcKK4BxYS0wyvZQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3FfpnN7jVV7VGi1MD%3D_xJEw04eCBzZcKK4BxYS0wyvZQ%40mail.gmail.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/CAMCvD%2BHTpvCcijwynz%2BgHFoz0QbnoU8LjBxfW-epU%3DMUbADiNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to