Developer: RhinoScript
Summary: Discusses to “include” or “use” functions from another source file.
I there a RhinoScript equivalent to what in C/C++ would be ”#include” or in Delphi “Uses” (where you can reference functions and such from another source file)?
I want to build a library of common functions that can be used from within other scripts, but I can't see how to reference an external file that would contain this stuff.
VBScript does not have an equivalent to the C/C++ ”#include” statement. But, its possible to write your own include-type function. For example:
' --------------------------------------------------------------------------- ' Subroutine: Include ' Purpose: Includes, or loads, other RhinoScript files ' Argument: A script file name to include ' Example: Call Include("C:\Scripts\MyScriptFile.rvb") ' --------------------------------------------------------------------------- Sub Include(strScriptName) Dim objFSO, objFile Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strScriptName) ExecuteGlobal objFile.ReadAll() objFile.Close End Sub
Also, if you have a number of script files that define utility functions and procedures that you would like to call from any source file, then consider adding these script files to the list of startup script file (Tools → Options →RhinoScript). See the RhinoScript help file for details.