How to invoke Python Script plugin f/ NppExec

NppExec
Dan Reilly
2012-12-20
2013-05-21
  • Dan Reilly
    Dan Reilly
    2012-12-20

    I want to invoke a Python Script plugin script from NppExec.  I see that there is support for npp_sendmsg.  One of the messages that can be sent is NPPM_MSGTOPLUGIN, which the Python Script plugin uses to communicate with other plugins.  So far, so good.  But, it appears that the parms I am passing from NppExec to PS are not what is required and scripts do not executed.  The format of the parms expected by the PS plugin are a bit complex and I can't find a way to create what is required.

    Is there any way to solve this problem?

    The format of the PS NPPM_MSGTOPLUGIN parms are described in the plugin Context-Help menu option:

    {…

        PythonScript_Exec pse;
        pse.structVersion = 1;
        HANDLE completeEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
        pse.completedEvent = completeEvent;
        pse.deliverySuccess = FALSE;
        TCHAR script = _T("e:\\script_to_run.py");
        pse.script = script;
        pse.flags = PYSCRF_SYNC;
        TCHAR pluginName = _T("PythonScript.dll");
        CommunicationInfo commInfo;
        commInfo.internalMsg = PYSCR_EXECSCRIPT;
        commInfo.srcModuleName = _T("MyPlugin.dll");
        commInfo.info = reinterpret_cast<void*>(&pse);
        BOOL delivery = SendMessage(nppData._nppHandle, NPPM_MSGTOPLUGIN, reinterpret_cast<WPARAM> (pluginName), reinterpret_cast<LPARAM>(&commInfo));

     
  • DV
    DV
    2012-12-20

    This is not possible currently and I do not see an easy way to do this since you need to use pointers to binary structures. 
    However, you can try to write a new (sub)plugin based on source code of NppExecPluginMsgTester that will provide some UI to NPPM_MSGTOPLUGIN parameters (actually you can implement support of any messages you wish) and then pass these parameters to NppExec for execution. Probably it sounds too complicated :) But if you have some experience in programming, I think it's completely achievable. Cheers!

     
  • DV
    DV
    2012-12-20

    Alternatively, you probably can invoke NppExec from Python Scrypt - i.e. otherwise than you suggested. Though I have no such deep knowledge of Python to advise whether it's possible to transform C++ examples from "NppExec\src\PluginCommunication\nppexec_msgs.h" to code in Python. 
    Anyway, it would be interesting to know your decision.