I am trying to run python module inside visual studio c#, but I get an error after line scope.Add = new Func((x, y) => x + y);.
Error: Missing compiler required member ‘Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create’
When I write a script in the main function (And referenced all required python .dll) :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IronPython;
using IronPython.Hosting;
using IronPython.Runtime;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using Microsoft.CSharp;
namespace Bob.Meshes {
public class pythonFromCShapr {
ScriptEngine engine = Python.CreateEngine();
public pythonFromCShapr() {
}
public void something() {
dynamic scope = engine.CreateScope();
scope.Add = new Func<int, int, int>((x, y) => x + y);
Console.WriteLine( scope.Add(2, 3));
}
}
}
Thank you for an answer. I did not know that there is Rhino.Runtime.PythonScript.
I would like to run networkX library for IronPython , but in grasshopper component.
I have used networkX in grasshopper using Python Component, but wondering if it possible to use several functions from this library in my custom component.
Nevertheless, I would like to ask much more simple question.
Could please show me a simple example using Rhino.Runtime.PythonScript when I want to execute python commands in C# component and get values from it?
I am curious however: what makes it more useful, for you to write Python inside a C# component? I am doubting there are actually many benefits, and debugging gets even more complicated.
Sorry, that’s pretty involved. You can check what GhPython does, if you want, in the GhPython source. I would suggest, however, not to maintain such a codebase, but it’s your choice.