Menu

Feature Request : send code to extern app

orenouard
2008-01-09
2013-03-15
  • orenouard

    orenouard - 2008-01-09

    Hi,

    It would be nice to have a way to execute a way to execute a system command on the selected portion of a python file in the text editor (taking it as a string argument). When working with an application that embedds a python interpreter (developping for Autodesk / Maya here), there is often a way to pass it a code snippet to be executed, being able to do that directly in context of the editor would be a great help (the command itself is dependant on the host application of course). It's not the same as running a python script in new instance of the application a with a run configuration, it's sending a code snippet to be executed in an already running instance. Anyone doing something similar here ?

    Basically it's a "run this <command> with selection (or clipboard) as argument" I'm looking for. As long as it's there and you can use a user defined command it would do the trick.

     
    • Fabio Zadrozny

      Fabio Zadrozny - 2008-01-09

      I don't think this really belongs into pydev... that could be something much more general (make this with any text from any selected editor).

      Maybe it's more in the context of:
      - http://eclipseexeditor.sourceforge.net/ (I think it has something close to what you're asking)
      - or maybe: http://www.wickedshell.net/

      Cheers,

      Fabio

       
    • orenouard

      orenouard - 2008-01-21

      You're right it's not PyDev specific, any kind of text from the text editor could be sent that way, as long as you know the command to communicate it to the target application.

      The thing is many Maya user switching to Python and looking for a good editor / IDE t the moment. And several users where I work have expressed they missed the possibility of other editors (like Jedit) to send code snippets to Maya in such a way. I know we are comparing apples and oranges here as an editor isn't an IDE like eclipse, and PyDev isn't the whole of Eclipse or even limited to a Text Editing extension.

      I'm also aware that when working on larger scale scripting projects, you'd be better off building modules and loading them in the host application rather than doing direct testing that way. But many casual scripters in the 3D studios work on small code functions or even direct "utility" scripts, and with Maya being more or less the leading DCC application switching to Python support, these is a lot of interest currently in finding good Python IDEs to use. Though Eclipse is arguably oversized for day to day script hacking in Maya, once you start doing more and organizing a larger script base I find it really great (being able to share the same IDE as for C/C++ work is an added benefit too).

      Actually there is no need for the extensions, the Eclipse "filter" (the "shift+alt+|" shortcut thing), will work if you define the correct command. For the couple of people who use PyDev with Maya I seen here (seen 2 of us so far :) ), if you want, it's very rough but basically working :

      Open a command port in Maya :

      commandPort -n "mayaCommand:7899";

      Create a new command to send the std input to Maya, for instance on Linux with this small Python script "pipeToMaya"

      #!/usr/bin/python
      import socket, sys
      port = 7899
      f = sys.stdin
      lines = f.readlines()
      f.close()
      script = ""
      multiLine = False
      if len(lines) == 1 :
          script = lines[0].replace('"', '\\"').strip('\n')
      else :
          for l in lines :
              script += l
          script = script.replace('\n', '\\n').replace('"', '\\"')
          multiLine = True
      # Annoying Maya call to Python formatting
      command = 'python("%s")' % script
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      sock.connect(('localhost',port))
      if multiLine :
          sock.sendall(command)
      else :
          sock.send(command)
          ret = sock.recv(4096)
          if ret is not None :
              print ret
      sock.close()

      Use "shift+alt+|" and enter "pipeToMaya" as command (for instance saved the script as such in /usr/local/bin and made it executable), and check "direct filter output to console".

      Of course would be more practical as a full fledged Eclipse Text Editor plugin, to be able to to that on a single button / option press and maybe to be able to change the port number, and application name in preferences, but I don't know enough about Eclipse pluging development or Java for that.

      Does it have an interest for other applications using an embedded Python interpreter I don't know, I have no idea if there are cases where it is handy to be able to send Python code snippets to the host application in a similar way of if Maya is just a peculiar case here.

       
MongoDB Logo MongoDB