Site Tools


This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:includefiles [2015/09/14] (current)
Line 1: Line 1:
 +====== Including Script Files ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //Discusses to "​include"​ or "​use"​ functions from another source file.//
 +===== Question =====
 +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. ​
 +===== Answer =====
 +VBScript does not have an equivalent to the C/C++ "#​include"​ statement. But, its possible to write your own include-type function. For example:
 +<code vb>
 +' ---------------------------------------------------------------------------
 +' 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.
 +{{tag>​Developer RhinoScript}}
developer/scriptsamples/includefiles.txt ยท Last modified: 2015/09/14 (external edit)