internal static string SetScriptedSend(ScriptEngine Engine, string Code) { try { ScriptRuntime Runtime = Engine.Runtime; Assembly MainAssembly = Assembly.GetExecutingAssembly(); string RootDir = Directory.GetParent(MainAssembly.Location).FullName; Runtime.LoadAssembly(MainAssembly); Runtime.LoadAssembly(typeof(String).Assembly); Runtime.LoadAssembly(typeof(Uri).Assembly); if (Engine.Setup.DisplayName.Contains("IronPython")) { string[] Results = PluginEditor.CheckPythonIndentation(Code); if (Results[1].Length > 0) { throw new Exception(Results[1]); } } ScriptSource Source = Engine.CreateScriptSourceFromString(Code); Source.ExecuteProgram(); return(""); } catch (Exception Exp) { return(Exp.Message); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { var path = @"C:\Users\darthoma\Documents\GitHub\honey-badger\examples\helloworld\helloworld.py"; var runtimeSetup = Python.CreateRuntimeSetup((IDictionary <string, object>)null); runtimeSetup.Options.Add("DivisionOptions", (object)PythonDivisionOptions.New); runtimeSetup.Options.Add("Frames", (object)true); runtimeSetup.Options.Add("Tracing", (object)true); ScriptRuntime scriptRuntime = new ScriptRuntime(runtimeSetup); scriptRuntime.LoadAssembly(typeof(RhinoApp).Assembly); scriptRuntime.LoadAssembly(typeof(int).Assembly); scriptRuntime.LoadAssembly(typeof(Form).Assembly); scriptRuntime.LoadAssembly(typeof(Color).Assembly); scriptRuntime.LoadAssembly(typeof(LengthExtension).Assembly); var engine = scriptRuntime.GetEngine("py"); var stream = new hbtestStdioStream(); scriptRuntime.IO.SetErrorOutput((Stream)stream, Encoding.Default); scriptRuntime.IO.SetOutput((Stream)stream, Encoding.Default); scriptRuntime.IO.SetInput((Stream)stream, Encoding.Default); ScriptScope scope = engine.CreateScope(); ScriptSource scriptSourceFromFile = engine.CreateScriptSourceFromFile( path, Encoding.Default, SourceCodeKind.Statements); scriptSourceFromFile.Execute(scope); var main = scope.GetVariable("main"); var result = main("hello, world"); RhinoApp.WriteLine($"executed: {result}"); }
protected ScriptManager() { Instance = this; messageReady = new AutoResetEvent(false); messageHandlers = new Dictionary <uint, MessageDelegate>(); eventMessageHandlers = new Dictionary <uint, Dictionary <uint, MessageDelegate> >(); messageQueue = new ConcurrentQueue <Message>(); scriptApi = new ScriptApi(); scriptApi.MessageHandler = (IScriptMessageHandler)this; //scriptApi.MessageHandler.HandleMessage = HandleMessage; //scriptApi.MessageHandler.HandleMessageEvent = HandleMessageEvent; scriptThread = new Thread(ScriptThreadStart); // it is possible to do this via configuration // i need to find an example to implement //engineRuntime = ScriptRuntime.CreateFromConfiguration(); //engine = engineRuntime.GetEngine("python"); engine = Python.CreateEngine(); engineRuntime = engine.Runtime; engineRuntime.LoadAssembly(typeof(string).Assembly); engineRuntime.LoadAssembly(typeof(Uri).Assembly); engineRuntime.LoadAssembly(this.GetType().Assembly); //engineScope = engine.CreateModule("Api"); //engineScope.SetVariable("MessageHandler", scriptApi.MessageHandler); // Dictionary<string, object> mh = new Dictionary<string, object>(); // mh.Add("__all__", new string[] { "HandleMessage", "HandleMessageEvent" }); // mh.Add("__dir__", new string[] { "HandleMessage", "HandleMessageEvent" }); // mh.Add("__name__", "MessageHandler"); // mh.Add("HandleMessage", ((IScriptMessageHandler)this).HandleMessage); // mh.Add("HandleMessageEvent", ((IScriptMessageHandler)this).HandleMessageEvent); //ScriptScope modScope = engine.CreateScope(mh); // modScope.SetVariable("HandleMessage", ((IScriptMessageHandler)this).HandleMessage); // modScope.SetVariable("HandleMessageEvent", ((IScriptMessageHandler)this).HandleMessageEvent); //Scope messageMod = HostingHelpers.GetScope(modScope); //modScope = engine.CreateScope(); //modScope.SetVariable("MessageHandler", messageMod); //Scope apiModule = HostingHelpers.GetScope(modScope); //engineRuntime.Globals.SetVariable("Api", apiModule); engineScope = engineRuntime.CreateScope(); scriptThread.Start(); }
private static void initAsNeeded() { if (_runtime != null) { return; } BugFixer.Run(); DebugUtil.Trigger(); string langQName = typeof(IronPython.Runtime.PythonContext).AssemblyQualifiedName; var langSetup = new LanguageSetup(langQName, "IronPython", new string[] { "IronPython", "Python", "py" }, new string[] { ".py" }); var setup = new ScriptRuntimeSetup(); langSetup.ExceptionDetail = true; // options can be found in ironpython2-ipy-2.7.7\Languages\IronPython\IronPython\Runtime\PythonOptions.cs langSetup.Options["Optimize"] = false; langSetup.Options["StripDocStrings"] = false; langSetup.Options["Frames"] = true; langSetup.Options["Tracing"] = true; // setup.LanguageSetups.Add(langSetup); //this is responsible for python being able to access private members on CLR objects: setup.PrivateBinding = true; _runtime = new ScriptRuntime(setup); _engine = _runtime.GetEngine("IronPython"); //This works for the simple purpose of creating a __main__ module //inspect.stack() should work after doing this. //Not sure if there's a better way. //This solution is from: //https://stackoverflow.com/questions/8264596/how-do-i-set-name-to-main-when-using-ironpython-hosted var pco = (IronPython.Compiler.PythonCompilerOptions)_engine.GetCompilerOptions(); pco.ModuleName = "__main__"; pco.Module |= IronPython.Runtime.ModuleOptions.Initialize; var source = Engine.CreateScriptSourceFromString(@"'''This is the __main__ module'''"); CompiledCode compiled = source.Compile(pco); mainScope = CreateScope(); compiled.Execute(mainScope); //more options string[] searchpaths = new string[] { System.IO.Path.Combine(Util.ModBasePath, "IronPython-2.7.7/Lib/"), System.IO.Path.Combine(Util.ModBasePath, "PythonModules/") }; _engine.SetSearchPaths(searchpaths); _runtime.LoadAssembly(System.Reflection.Assembly.GetExecutingAssembly()); _runtime.LoadAssembly(typeof(Verse.Game).Assembly); }
public PythonRegistry(string pythonPath) { ScriptEngine engine = Python.CreateEngine(); ScriptRuntime runtime = engine.Runtime; scope = engine.CreateScope(); source = engine.CreateScriptSourceFromFile(pythonPath); runtime.LoadAssembly(typeof(NodeStructure).Assembly); runtime.LoadAssembly(typeof(Variable).Assembly); source.Execute(scope); scope.GetVariable("RegisterAll")(new RegisterProxy(this)); }
public PythonEngine(ContentManager content) { ScriptRuntime runtime = Python.CreateRuntime(new Dictionary <string, object> { #if DEBUG { "Debug", true }, #endif }); var interopClasses = new[] { typeof(BaseEntity), typeof(Microsoft.Xna.Framework.Graphics.Texture2D), typeof(Jv.Games.Xna.Sprites.Sprite), }; foreach (var interopType in interopClasses) { runtime.LoadAssembly(Assembly.GetAssembly(interopType)); } Engine = runtime.GetEngine("py"); var paths = Engine.GetSearchPaths(); paths.Add("PlayerScripts"); paths.Add(Path.Combine(content.RootDirectory, "Scripts")); paths.Add(Path.Combine(content.RootDirectory, "Scripts/Entities")); Engine.SetSearchPaths(paths); }
public void ReloadScripts(ScriptExecutionCallback scriptExecutionCallback) { Shutdown(); ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup(); scriptRuntimeSetup.LanguageSetups.Add(new LanguageSetup("IronPython.Runtime.PythonContext, IronPython", "IronPython 2.6", new[] { "IronPython", "Python", "py" }, new[] { ".py" })); scriptRuntimeSetup.LanguageSetups.Add(new LanguageSetup("IronRuby.Runtime.RubyContext, IronRuby", "IronRuby 1.0", new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" })); scriptRuntimeSetup.LanguageSetups[0].Options.Add("SearchPaths", @"Libraries\IronPython".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options.Add("SearchPaths", @"Libraries\IronRuby\IronRuby;Libraries\IronRuby\ruby;Libraries\IronRuby\ruby\site_ruby;Libraries\IronRuby\ruby\site_ruby\1.8;Libraries\IronRuby\ruby\1.8".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options.Add("LibraryPaths", @"Libraries\IronRuby\IronRuby;Libraries\IronRuby\ruby;Libraries\IronRuby\ruby\site_ruby;Libraries\IronRuby\ruby\site_ruby\1.8;Libraries\IronRuby\ruby\1.8".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options["KCode"] = RubyEncoding.KCodeUTF8; scriptRuntimeSetup.LanguageSetups[1].ExceptionDetail = true; _scriptRuntime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, scriptRuntimeSetup); foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { _scriptRuntime.LoadAssembly(asm); } _scriptScopes = new Dictionary <string, ScriptScope>(); PrepareScriptScopeByPath("*Eval*"); _scriptRuntime.Globals.SetVariable("Session", _sessionProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("Server", _serverProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("CurrentSession", _sessionProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("CurrentServer", _serverProxy.GetTransparentProxy()); // 共通のスクリプトを読む LoadScriptsFromDirectory(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "GlobalScripts"), scriptExecutionCallback); // ユーザごとのスクリプトを読む LoadScriptsFromDirectory(Path.Combine(CurrentSession.UserConfigDirectory, "Scripts"), scriptExecutionCallback); }
public ScriptManager(string scriptsDir, string pythonLibsDir) { _scripts = new Dictionary <string, Script>(); ScriptRuntime runtime = Python.CreateRuntime(); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { runtime.LoadAssembly(assembly); } _scriptEngine = runtime.GetEngine("py"); var paths = _scriptEngine.GetSearchPaths(); if (!string.IsNullOrEmpty(scriptsDir)) { paths.Add(scriptsDir); } if (!string.IsNullOrEmpty(pythonLibsDir)) { paths.Add(pythonLibsDir); } _scriptEngine.SetSearchPaths(paths); }
private static string[] GetScriptInfo(string path, int t) { ScriptEngine engine; ScriptRuntime runtime = null; try { engine = Python.CreateEngine(); var pc = HostingHelpers.GetLanguageContext(engine) as PythonContext; var hooks = pc.SystemState.Get__dict__()["path_hooks"] as List; hooks.Clear(); ScriptSource source = engine.CreateScriptSourceFromFile(path); CompiledCode code = source.Compile(); ScriptScope scope = engine.CreateScope(); runtime = engine.Runtime; Assembly assembly = typeof(Program).Assembly; runtime.LoadAssembly(Assembly.LoadFile(assembly.Location)); source.Execute(scope); dynamic pyClass = scope.GetVariable("Mml2vgmScript"); dynamic mml2vgmScript = pyClass(); switch (t) { case 0: return(mml2vgmScript.title().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); case 1: return(mml2vgmScript.scriptType().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); case 2: return(mml2vgmScript.supportFileExt().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); case 3: string ret = mml2vgmScript.defaultShortCutKey(); if (!string.IsNullOrEmpty(ret)) { return(ret.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); } break; } } catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) { ;//無視 } catch (Exception ex) { log.ForcedWrite(ex); } finally { if (runtime != null) { runtime.Shutdown(); } GC.Collect(); } return(new string[] { "" });// Path.GetFileName(path); }
public IronScriptEngine(ScriptEngine Engine) { ScriptRuntime RunTime = Engine.Runtime; RunTime.IO.SetOutput(OutputStream, Encoding.UTF8); RunTime.IO.SetErrorOutput(OutputStream, Encoding.UTF8); ScriptScope Scope = Engine.CreateScope(); Assembly MainAssembly = Assembly.GetExecutingAssembly(); string RootDir = Directory.GetParent(MainAssembly.Location).FullName; RunTime.LoadAssembly(MainAssembly); RunTime.LoadAssembly(typeof(String).Assembly); RunTime.LoadAssembly(typeof(Uri).Assembly); this.Engine = Engine; this.Scope = Scope; }
static void Main(string[] args) { // Setup DLR ScriptRuntime with our languages. We hardcode them here // but a .NET app looking for general language scripting would use // an app.config file and ScriptRuntime.CreateFromConfiguration. var setup = new ScriptRuntimeSetup(); string qualifiedname = typeof(VBScriptContext).AssemblyQualifiedName; setup.LanguageSetups.Add(new LanguageSetup( qualifiedname, "vbscript", new[] { "vbscript" }, new[] { ".vbs" })); var dlrRuntime = new ScriptRuntime(setup); // Don't need to tell the DLR about the assemblies we want to be // available, which the SymplLangContext constructor passes to the // Sympl constructor, because the DLR loads mscorlib and System by // default. //dlrRuntime.LoadAssembly(typeof(object).Assembly); dlrRuntime.LoadAssembly(typeof(global::Dlrsoft.VBScript.Runtime.BuiltInFunctions).Assembly); // Get a Sympl engine and run stuff ... var engine = dlrRuntime.GetEngine("vbscript"); //string filename = @"..\..\test\test.vbs"; string filename = args[0]; var scriptSource = engine.CreateScriptSourceFromFile(filename); var compiledCode = scriptSource.Compile(); var feo = engine.CreateScope(); //File Level Expando Object //feo = engine.ExecuteFile(filename, feo); feo.SetVariable("response", System.Console.Out); compiledCode.Execute(feo); Console.WriteLine("Type any key to continue.."); Console.Read(); }
public ScriptHandler() { _runtime = Ruby.CreateRuntime(); _runtime.LoadAssembly(GetType().Assembly); _engine = Ruby.GetEngine(_runtime); _scope = _engine.CreateScope(); }
public AspHost(AspHostConfiguration config) { _config = config; ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); if (config != null && config.Trace) { setup.Options["Trace"] = ScriptingRuntimeHelpers.True; } string qualifiedname = typeof(VBScriptContext).AssemblyQualifiedName; setup.LanguageSetups.Add(new LanguageSetup( qualifiedname, "vbscript", new[] { "vbscript" }, new[] { ".vbs" })); _runtime = new ScriptRuntime(setup); if (config != null && config.Assemblies != null) { foreach (Assembly a in config.Assemblies) { _runtime.LoadAssembly(a); } } _engine = _runtime.GetEngine("vbscript"); }
static public void Run(string filePath) { // Setup DLR ScriptRuntime with our languages. We hardcode them here // but a .NET app looking for general language scripting would use // an app.config file and ScriptRuntime.CreateFromConfiguration. var setup = new ScriptRuntimeSetup(); string qualifiedname = typeof(VBScriptContext).AssemblyQualifiedName; setup.LanguageSetups.Add(new LanguageSetup( qualifiedname, "vbscript", new[] { "vbscript" }, new[] { ".vbs" })); var dlrRuntime = new ScriptRuntime(setup); //Add the VBScript runtime assembly dlrRuntime.LoadAssembly(typeof(global::Dlrsoft.VBScript.Runtime.BuiltInFunctions).Assembly); // Get a VBScript engine and run stuff ... var engine = dlrRuntime.GetEngine("vbscript"); var scriptSource = engine.CreateScriptSourceFromFile(filePath); var compiledCode = scriptSource.Compile(); var feo = engine.CreateScope(); //feo = engine.ExecuteFile(filename, feo); feo.SetVariable("Assert", new NunitAssert()); compiledCode.Execute(feo); }
private void loadRunTime() { m_output = new MemoryStream(); m_runTime = ScriptRuntime.CreateFromConfiguration(); m_runTime.IO.SetOutput(m_output, new StreamWriter(m_output)); m_runTime.IO.SetErrorOutput(m_output, new StreamWriter(m_output)); Assembly pluginsAssembly = Assembly.LoadFile(IO.IOHelper.MapPath(IO.SystemDirectories.Bin + "/umbraco.dll")); m_runTime.LoadAssembly(pluginsAssembly); m_runTime.LoadAssembly(typeof(String).Assembly); m_runTime.LoadAssembly(typeof(Uri).Assembly); m_runTime.LoadAssembly(typeof(umbraco.presentation.nodeFactory.Node).Assembly); }
public static void AddReferences(this ScriptRuntime runtime, params Assembly[] assemblies) { foreach (var assembly in assemblies) { runtime.LoadAssembly(assembly); } }
/// <summary> /// Load default references into the runtime, including this assembly /// and a select set of platform assemblies. /// </summary> /// <param name="runtime">Pre-initialized ScriptRuntime to load assemblies into.</param> public static void LoadDefaultAssemblies(ScriptRuntime runtime) { foreach (string name in new string[] { "mscorlib", "System", "System.Windows", "System.Windows.Browser", "System.Net" }) { runtime.LoadAssembly(runtime.Host.PlatformAdaptationLayer.LoadAssembly(name)); } }
private void CreateRvtModuleInEnviroment() { _pythonScriptRuntime.LoadAssembly(Assembly.Load("RevitAPI")); _pythonScriptRuntime.LoadAssembly(Assembly.Load("RevitAPIUI")); _externalEventPythonScriptPath = new ExternalPythonScriptSetting(); ScriptScope rvt = _pythonEngine.CreateModule("rvt"); rvt.SetVariable("_app_", _applicaton); rvt.SetVariable("_event_path_", _externalEventPythonScriptPath); rvt.SetVariable("_handler_", _engineInstance); ExternalEvent exEvent = ExternalEvent.Create(_engineInstance); rvt.SetVariable("_event_", exEvent); rvt.SetVariable("_variables_", _scriptVariables); }
public IronPythonScriptEngine() { runtime = engine.Runtime; runtime.LoadAssembly(Assembly.GetAssembly(typeof(Mogre.Vector3))); scope = runtime.CreateScope(); // install built-in scripts install(new Script(builtin)); }
private void InitPythonEngine() { _engine = Python.CreateEngine(); _runtime = _engine.Runtime; _runtime.LoadAssembly(typeof(Wartorn.UIClass.Console).Assembly); _scope = _engine.CreateScope(); _scope.SetVariable("log", log); _scope.SetVariable("console", this); }
internal static string SetScriptedSend(ScriptEngine Engine, string Code) { try { ScriptRuntime Runtime = Engine.Runtime; Assembly MainAssembly = Assembly.GetExecutingAssembly(); string RootDir = Directory.GetParent(MainAssembly.Location).FullName; Runtime.LoadAssembly(MainAssembly); Runtime.LoadAssembly(typeof(String).Assembly); Runtime.LoadAssembly(typeof(Uri).Assembly); ScriptSource Source = Engine.CreateScriptSourceFromString(Code); Source.ExecuteProgram(); return(""); } catch (Exception Exp) { return(Exp.Message); } }
void InitRuntime(ScriptRuntime runtime) { runtime.IO.SetOutput(m_scriptOutputStream, System.Text.Encoding.Unicode); runtime.IO.SetErrorOutput(m_scriptOutputStream, System.Text.Encoding.Unicode); foreach (var assemblyName in new string[] { "Dwarrowdelf.Common", "Dwarrowdelf.Server.World" }) { var assembly = runtime.Host.PlatformAdaptationLayer.LoadAssembly(assemblyName); runtime.LoadAssembly(assembly); } }
private MacroInvoker() { ScriptRuntime runtime = _engine.Runtime; runtime.LoadAssembly(Assembly.GetExecutingAssembly()); if (_importCache == null) { _importCache = InitializeImports(_engine); } }
internal static ScriptEngine GetScriptEngine() { ScriptRuntimeSetup Setup = new ScriptRuntimeSetup(); Setup.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup()); Setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null)); ScriptRuntime RunTime = new ScriptRuntime(Setup); ScriptEngine Engine = RunTime.GetEngine("py"); ScriptScope Scope = RunTime.CreateScope(); Assembly MainAssembly = Assembly.GetExecutingAssembly(); string RootDir = Directory.GetParent(MainAssembly.Location).FullName; RunTime.LoadAssembly(MainAssembly); RunTime.LoadAssembly(typeof(String).Assembly); RunTime.LoadAssembly(typeof(Uri).Assembly); RunTime.LoadAssembly(typeof(XmlDocument).Assembly); Engine.Runtime.TryGetEngine("py", out Engine); return(Engine); }
/// <summary> /// Creates new instance of IPy engine with given stream /// </summary> /// <param name="iostream">stream object to be used for I/O</param> /// <remarks></remarks> public IPyEngine(System.IO.Stream iostream, bool AddExecutingAssembly = true) { this.Engine = Python.CreateEngine(); Runtime = this.Engine.Runtime; EngineScope = this.Engine.CreateScope(); _io = iostream; SetStreams(_io); if (AddExecutingAssembly) { Runtime.LoadAssembly(Assembly.GetExecutingAssembly()); } }
public VbscriptHost() { var setup = new ScriptRuntimeSetup(); string qualifiedname = typeof(VBScriptContext).AssemblyQualifiedName; setup.LanguageSetups.Add(new LanguageSetup( qualifiedname, "vbscript", new[] { "vbscript" }, new[] { ".vbs" })); setup.HostType = typeof(BrowserScriptHost); _runtime = new ScriptRuntime(setup); _engine = _runtime.GetEngine("vbscript"); _runtime.LoadAssembly(typeof(VBScriptContext).Assembly); }
private void RunFromFile() { var salesBasket = new SalesBasket() { Lines = new List <Line>() { new Line { ProductName = "Prod1", ProductPrice = 100, Quantity = 2, Amount = 100 * 2 }, new Line { ProductName = "Prod2", ProductPrice = 20, Quantity = 1, Amount = 20 * 1 }, new Line { ProductName = "Prod3", ProductPrice = 45.8, Quantity = 2, Amount = 45.8 * 2 }, new Line { ProductName = "Prod4", ProductPrice = 3.9, Quantity = 10, Amount = 3.9 * 10 }, new Line { ProductName = "Prod5", ProductPrice = 555.5, Quantity = 10, Amount = 555.5 * 10 } } }; string dir = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName; string pythonDir = Path.Combine(dir, "PythonScripting"); var files = new List <string>(); foreach (string path in Directory.GetFiles(pythonDir)) { if (path.ToLower().EndsWith(".py")) { files.Add(path); } } string libPath = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "TestConsoleApp.exe"); Assembly assembly = Assembly.LoadFile(libPath); runtime.LoadAssembly(assembly); scope.SetVariable("salesBasket", salesBasket); foreach (var file in files) { Console.WriteLine("\nFrom Python file {0}", file); ScriptSource source = engine.CreateScriptSourceFromFile(file); source.Execute(scope); } }
public MacroInvoker() { ScriptRuntime runtime = _engine.Runtime; runtime.LoadAssembly(Assembly.GetExecutingAssembly()); foreach (string assembly in AssistantOptions.Assemblies ?? new string[0]) { try { runtime.LoadAssembly(Assembly.LoadFile(assembly)); } catch (Exception) { // ignored } } if (_importCache == null) { _importCache = InitializeImports(_engine); } _engine.Runtime.IO.SetOutput(_memoryStream, _textWriter); _engine.Runtime.IO.SetErrorOutput(_memoryStream, _textWriter); string modulePath = Path.Combine(Engine.StartupPath ?? Environment.CurrentDirectory, "Modules"); ICollection <string> searchPaths = _engine.GetSearchPaths(); if (searchPaths.Contains(modulePath)) { return; } searchPaths.Add(modulePath); _engine.SetSearchPaths(searchPaths); }
internal Host() { _output = new MemoryStream(); _error = new MemoryStream(); var configFile = Path.GetFullPath(Uri.UnescapeDataString(new Uri(typeof(Host).Assembly.CodeBase).AbsolutePath)) + ".config"; _runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile)); _engine = _runtime.GetEngine("py"); _runtime.Globals.SetVariable("prompt", Form1.PromptString); _theScope = _engine.CreateScope(); _runtime.IO.SetOutput(_output, new StreamWriter(_output)); _runtime.IO.SetErrorOutput(_error, new StreamWriter(_error)); _runtime.LoadAssembly(Assembly.GetAssembly(typeof(Circle))); }
public Engine(string filePath, Inventor.PlanarSketch oSketch, Inventor.Application oApp, double slotHeight, double slotWidth) { _engine = Python.CreateEngine(new Dictionary <string, object>() { { "Frames", true }, { "FullFrames", true } }); _runtime = _engine.Runtime; Assembly invAssembly = Assembly.LoadFile(@"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop\v4.0_17.0.0.0__d84147f8b4276564\Autodesk.Inventor.interop.dll"); _runtime.LoadAssembly(invAssembly); _scope = _engine.CreateScope(); //Make variable names visible within the python file. These string names will be used an arguments in the python file. _scope.SetVariable("oPlanarSketch", oSketch); _scope.SetVariable("oApp", oApp); _scope.SetVariable("slotHeight", slotHeight); _scope.SetVariable("slotWidth", slotWidth); ScriptSource _script = _engine.CreateScriptSourceFromFile(filePath); _code = _script.Compile(); }