Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Must use for .Net developers, the Python namespace can be used in any script editor inside your project environment (Tasks, Classes and CodeBehind). Basically, all you need is to install Python for .NET.

The Python namespace provides several .Net methods to interact with Python codes and objects. See some of those methods below:                        

...

  • Run a Python code using Python for .NET.
Code Block
string ExecuteCode(string code, string workingDirectory = null, Dictionary<string, object> locals = null, bool keepValuesAsPython = false)

string code = py file name
string workingDirectory = Working directory. It will be added in 'sys.path'
Dictionary<string, object> locals = Local variables inside Python code. Default is null.
bool keepValuesAsPython = Keep retuned values as Python objects or convert to .NET objects. Default is false.
string return = If success return null else string contains error.


  • Convert a Python value to .NET value.
Code Block
public static object FromPython(object value)

object value = Python value
object returns = NET value


  • Copy a Python object to a tag (Array or User Template).
Code Block
public static void CopyPythonObjectToTag(object source, string tagName)

object source = Python object.
string tagName = Tag Array or User Template.


  • Copy a tag (Array or User Template) to a Python object.
Code Block
public static void CopyTagToPythonObject(string tagName, object target)

string tagName = Tag Array or User Template.
object target = Python object.


  • Create a Python object from a Python class.
Code Block
public static object CreatePythonObjectFromPyFile(string pyFileName, string className, object[] parameters = null, string tagName = null)

string pyFileName = Python file name containg the definition of Python class.
string className = Python class name.
object[] parameters = Parameters for Python class while creating Python object.
string tagName = Tag name (Optional, Tag Array or User Template). If tag exists then copy all values to new Python object.
object returns = Reference to new Python object.


  • Get all attributes of a Python object.
Code Block
public static IDictionary<string, object> GetAttributesPythonObject(object pythonObject, bool keepValuesAsPython = false)

object pythonObject = Python object/
bool keepValuesAsPython = Keep retuned values as Python objects or convert to .NET objects. Default is false.
IDictionary<string, object> = Dictionary contains attributes (name and value).


  • Set a new value for attributes of a Python object.
Code Block
public static void SetAttributesPythonObject(object pythonObject, IDictionary<string, object> dic)

object pythonObject = Python object.
IDictionary<string, object> = Dictionary contains attributes (name and value) for setting.


  • Dump a python object to a string to send to a TraceWindow.
Code Block
public static string DumpPythonObjectToString(object pythonObject)

object pythonObject = Python object.
string returns = Dump information of object.


Note

If you need others other Python modules and libraries (such as numpy, pythonnet, matplotlib, etc.) must be installed at same location Python Engine (python.exe).

...