PythonScript

References
public abstract class PythonScript
Represents a Python script.

Constructors

PythonScript

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

Properties

ContextId

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

Output

#Since v5.0
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.

public Action<string> Output { get; set; }

ScriptContextCommand

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

ScriptContextDoc

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

SearchPaths

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

Methods

AddRuntimeAssembly

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

Compile

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

ContainsVariable

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

Create

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

CreateTextEditorControl

#Since v5.0
Creates a control where the user is able to type Python code.
public abstract object CreateTextEditorControl(
script,
A starting script.
helpcallback
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
Evaluates statements and an expression in the main scripting context.
public abstract object EvaluateExpression(
statements,
One or several statements.
expression
An expression.
)
The expression result.

ExecuteFile

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

ExecuteFileInScope

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

ExecuteScript

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

GetSearchPaths

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

GetStackTraceFromException

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

GetVariable

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

GetVariableNames

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

RemoveVariable

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

RuntimeAssemblies

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

SetIntellisenseVariable

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

SetSearchPaths

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

SetupScriptContext

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

SetVariable

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