Forgot password?

Create an account!


« back

RhinoScript – Script equivalent to "Include" or "Uses"


Please log in to write a message.

  • 4. Hanno (Mar 01, 2011 09.18):


    I'm actually doing a similar thing. I have a short Rhinoscript file defining some path constants which I put into the "scripts to load when Rhino starts". So it's like environment variables without all the hassle of reading them from within VBscript.


  • 3. carlolsen (Mar 01, 2011 01.17):


    Your code plus "LastLoadedScriptFile" as you suggested seems to do the job. I did find that you need to load a script from within Rhino before LastLoadedScriptFile would return anything other than a null, though. Perhaps this is not a problem when running from within Rhino, but can be a gotcha first time you run from within the script editor.

    Anyway, this works, so thank you!

    I think the final solution I am going to settle on, though, will be to place the script library in some sub folder of a common windows folder, and then read the environment variable to get the Windows part of the folder name, and add to it my sub folders (or do something similar, setting my own private environment variable to point to the library). This may seem a bit convoluted, but it works in the bigger picture of what I am doing that is more than I care to explain here.



  • 2. Hanno (Feb 28, 2011 12.18):


    VBScript knows ExecuteGlobal which parses any string as program code in global environment. You can use this to load script libraries. The Rhino.rvb shown in the RhinoScript help defines the following function:

    Public Function Include (strScriptName)

    Dim oFS, oFile

      Set oFS = CreateObject("Scripting.FileSystemObject")

      Set oFile = oFS.OpenTextFile(strScriptName)

      ExecuteGlobal oFile.ReadAll()


      Include = Null

    End Function

    However, the problem is that the current path is always the Rhino program path. You can use Rhino.LastLoadedScriptFile or Rhino.DocumentPath to construct paths relative to your script or model.

    Hope that helps!


  • 1. carlolsen (Feb 25, 2011 19.36):

    I want to create a library of commonly used functions for my scripts and place them in a separate file.

    Is there a RhinoScript equivalent of "uses" in Dephi or "include" in C that can do this?

    It WILL be the case that my library code will reside in the same folder as my scripts (or maybe a sub-folder), but I won't be able to know the ABSOLUTE path, as that will depend on where the end user decides to keep their scripts. (So I need a solution that does not rely on an absolute path to the files.)




Why are these buttons gray?