PythonScript

References
public abstract class PythonScript
Represents a Python script.

Constructors

PythonScript

#
protected PythonScript()
Initializes a new instance of the PythonScript class.

Properties

ContextId

#Since v5.0
public int ContextId { get; set; }
Gets or sets a context unique identified.

Output

#Since v5.0
public Action<string> Output { get; set; }
Gets or sets the Python script "print()" target.

By default string output goes to the Rhino.RhinoApp.Write function. Set Output if you want to redirect the output from python to a different function while this script executes.

ScriptContextCommand

#Since v6.0
public Command ScriptContextCommand { get; set; }
Command associated with this script. Used for localiation

ScriptContextDoc

#Since v5.0
public object ScriptContextDoc { get; set; }
object set to variable held in scriptcontext.doc.

SearchPaths

#Since v7.1
public static string[] SearchPaths { get; set; }
Get/Set additional search paths used by the python interpreter

Methods

AddRuntimeAssembly

#Since v7.0
public static void AddRuntimeAssembly(Assembly assembly)
Add assembly to list of assemblies used by python
assembly (Assembly)

Compile

#Since v5.0
public abstract PythonCompiledCode Compile(string script)
Compiles a class in a quick-to-execute proxy.
script (string)A string text.
A Python compiled code instance.

ContainsVariable

#Since v5.0
public abstract bool ContainsVariable(string name)
Determines if the main scripting context has a variable with a name.
name (string)The variable name.
true if the variable is present.

Create

#Since v5.0
public static PythonScript Create()
Constructs a new Python script context.
A new Python script, or null if none could be created. Rhino 4 always returns null.

CreateTextEditorControl

#Since v5.0
public abstract object CreateTextEditorControl(string script, Action<string> helpcallback)
Creates a control where the user is able to type Python code.
script (string)A starting script.
helpcallback (Action<string>)A method that is called when help is shown for a function, a class or a method.
A Windows Forms control.

EvaluateExpression

#Since v5.0
public abstract object EvaluateExpression(string statements, string expression)
Evaluates statements and an expression in the main scripting context.
statements (string)One or several statements.
expression (string)An expression.
The expression result.

ExecuteFile

#Since v5.0
public abstract bool ExecuteFile(string path)
Executes a Python file. The file is executed in a new, __main__ scope.
path (string)The path to the file.
true if the file executed. This method can throw scripting-runtime based exceptions.

ExecuteFileInScope

#Since v7.0
public abstract bool ExecuteFileInScope(string path)
Executes a Python file in the calling script scope. All old variables are kept.
path (string)The path to the file.
true if the file executed. This method can throw scripting-runtime based exceptions.

ExecuteScript

#Since v5.0
public abstract bool ExecuteScript(string script)
Executes a Python string.
script (string)A Python text.
true if the file executed. This method can throw scripting-runtime based exceptions.

GetSearchPaths

#
protected abstract string[] GetSearchPaths()
Protected helper function for static SearchPaths

GetStackTraceFromException

#Since v5.0
public abstract string GetStackTraceFromException(Exception ex)
Retrieves a meaningful representation of the call stack.
ex (Exception)An exception that was thrown by some of the methods in this class.
A string that represents the Python exception.

GetVariable

#Since v5.0
public abstract object GetVariable(string name)
Gets the object associated with a variable name in the main scripting context.
name (string)A variable name.
The variable object.

GetVariableNames

#Since v5.0
public abstract IEnumerable<string> GetVariableNames()
Retrieves all variable names in the script.
An enumerable set with all names of the variables.

RemoveVariable

#Since v5.0
public abstract void RemoveVariable(string name)
Removes a defined variable from the main scripting context.
name (string)The variable name.

RuntimeAssemblies

#Since v7.0
public static Assembly[] RuntimeAssemblies()
Get list of assemblies used by python for library browser and inclusion into the runtime

SetIntellisenseVariable

#Since v5.0
public virtual void SetIntellisenseVariable(string name, object value)
Sets a variable for runtime introspection.
name (string)A variable name.
value (object)A variable value.

SetSearchPaths

#
protected abstract void SetSearchPaths(string[] paths)
Protected helper function for static SearchPaths
paths (string[])

SetupScriptContext

#Since v6.0
public virtual void SetupScriptContext(object doc)
Setups the script context. Use a RhinoDoc instance unless unsure.
doc (object)Document.

SetVariable

#Since v5.0
public abstract void SetVariable(string name, object value)
Sets a variable with a name and an object. Object can be null (Nothing in Visual Basic).
name (string)A valid variable name in Python.
value (object)A valid value for that variable name.