ExecuteScript (Application)

Description

Executes a script file. This routine allows a single plug-in to be written with more than one language. For example, a VBScript script could call a helper function written in JScript. It is also a useful way for a COM C++ plug-in to execute script code.

Alternatively, you can register the script as a custom command. One advantage of that approach is that the calling script does not need to know the full path to the called script.

If there is an error the global ErrorInfo contains detailed information, For example, if there was a parsing error or script error the details of what went wrong are recorded in the ErrorInfo.Description property and the line number is recorded in the ErrorInfo.HelpContext property. How you can extract this information depends on the language; for example, see 'GetErrorInfo()' in C++, 'err' in VBScript, and 'Error object' in JScript.

Scripting Syntax

    Application.ExecuteScript( FileName, [Language], [ProcName], [Params] )

C# Syntax

    Object Application.ExecuteScript( String in_FileName, String in_LanguageProgID, String in_ProcName, Object& io_Params );

Parameters

Parameter | Type | Description
FileName | String or Expression | Full path to the script file
Language | String or Expression | Language used to author the script. Default Value: Determined based on filename extension. Possible Values: • VBScript: VBScript language (the only recognized filename extension is '.vbs') • JScript: JScript language (the only recognized filename extension is '.js') • Python: Python ActiveX scripting language (the only recognized filename extensions are '.py' and '.pys') • PythonScript: Python ActiveX scripting language (the only recognized filename extensions are '.py' and '.pys') • PerlScript: Perl scripting language (the only recognized filename extensions are '.pl' and '.pls')
ProcName | String | Name of subroutine to execute. By the nature of scripting languages, any global code (code that is not part of a subroutine) is also executed. Tip: In VBScript subroutines are called "sub" or "function", in JScript "function", in PerlScript "sub", and in Python "def".
Params | Array of Variants | Arguments to pass to subroutine

Return Value

A Variant containing the return value of the procedure

Examples

VBScript Example

    Dim fso, wText, bInteractive, TestFile
    TestFile="c:\temp\test.vbs"

    Main()

    '------------------------------------------------------------------------------
    ' NAME: FillFile
    '
    ' INPUT:
    '
    ' DESCRIPTION: Fill the test file
    '------------------------------------------------------------------------------
    sub FillFile (in_file)
       wText.WriteLine "Main()"
       wText.WriteLine ""

       wText.WriteLine "sub log_some_messages(an_int, a_string)"
       wText.WriteLine "logmessage ""the int : "" & an_int"
       wText.WriteLine "logmessage ""the string : "" & a_string"
       wText.WriteLine "end sub"
       wText.WriteLine ""

       wText.WriteLine "sub main()"
       wText.WriteLine "CreatePrim ""Sphere"", ""NurbsSurface"""
       wText.WriteLine "end sub"
       wText.Close
    end sub

    sub main()
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set wText = fso.CreateTextFile( TestFile, 1)

       FillFile TestFile

       ExecuteScript TestFile

       dim aParams
       aParams = Array(123456789, "toto")
       ExecuteScript TestFile,,"log_some_messages", aParams
    end sub

See Also

XSIApplication.ExecuteScriptCommand | Application.ExecuteScriptCode

Autodesk Softimage v7.5