TextScriptInterpreter: Server basics

From The Foundry MODO SDK wiki
Jump to: navigation, search

A TextScriptInterpreter is a plug-in server that runs a text buffer as a script.


When running scripts and macros, nexus uses script-interpreter servers. When presented with an unknown script it enumerates the servers until it finds one that recognizes the file, and then it passes control to the interpreter. When the script completes the interpreter returns an optional message. The script functions by querying ScriptQuery interfaces to read state and firing commands to perform actions.



  • LXsSAV_DOSPATTERN -- the DOS-format search string for finding appropriate script files (e.g. "*.pl").

Sample Methods

The plug-in server class derives from CLxImpl_TextScriptInterpreter, and exports the ILxTextScriptInterpreter interface.


The ValidateFileType() method is called to quickly check if a file matches this interpreter. This is meant to be fast, so typically interpreters use their name on the first line of the script as a key.

tsi_ValidateFileType (
        ILxUnknownID            script,
        const char             *firstList)     LXx_OVERRIDE
        if (!strstr (firstLine, "myscript"))
                return LXe_SCRIPT_UNKNOWN;

        return LXe_OK;

The Run() method executes the script. The text is read from the script object, and its contents interpreted. In this example it's a very simple macro interpreter, executing each line as a command. If an error occurs it can be reported through the message object.

tsi_Run (
        ILxUnknownID		 script,
        int			 execFlags,
        const char		*args,
        ILxUnknownID		 message)       LXx_OVERRIDE
        CLxUser_Script          scr (script);
        CLxUser_CommandService  cmd_srv;
        const char             *buf, *line;
        unsigned                len;

        scr.GetBuffer (&buf, &size);

        while (line = get_next_line (buf, line)) {
                rc = cmd_srv.ExecuteArgString (-1, LXiCTAG_NULL, line);
                if (LXx_FAIL (rc)) {
                        CLxUser_Message         msg (message);
                        msg.SetCode (LXe_WARNING);
                        msg.SetMsg ("mymessagetable", "myerrormessagekey");
                        return LXe_FAILED;
        return LXe_OK;