Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is possible. You just need to add search paths to ScriptEngine object like this:</p> <pre><code>var paths = engine.GetSearchPaths(); paths.Add(yourLibsPath); // add directory to search </code></pre> <p>or</p> <pre><code>engine.SetSearchPaths(paths); </code></pre> <p>Then you could use any module in directories, which you add:</p> <pre><code>import pyFileName # without extension .py </code></pre> <p><strong>Update</strong> OK. If you want to use embedded resource strings like module, you may use this code:</p> <pre><code>var scope = engine.CreateScope(); // Create ScriptScope to use it like a module engine.Execute("import clr\n" + "clr.AddReference(\"System.Windows.Forms\")\n" + "import System.Windows.Forms\n" + "def Hello():\n" + "\tSystem.Windows.Forms.MessageBox.Show(\"Hello World!\")", scope); // Execute code from string in scope. </code></pre> <p>Now you have a ScriptScope object (<strong>scope</strong> in code) containing all executed functions. And you may insert them into another scope like this:</p> <pre><code>foreach (var keyValuePair in scope.GetItems()) { if(keyValuePair.Value != null) anotherScope.SetVariable(keyValuePair.Key, keyValuePair.Value); } </code></pre> <p>Or you can execute your scripts right in this ScriptScope:</p> <pre><code>dynamic executed = engine.ExecuteFile("Filename.py", scope); executed.SomeFuncInFilename(); </code></pre> <p>And in this script you may use all functions without <strong>import</strong>:</p> <pre><code>def SomeFuncInFilename(): Hello() # uses function from your scope </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload