Platforms to show: All Mac Windows Linux Cross-Platform

Back to PythonMBS class.

PythonMBS.AddCustomFunction(FunctionName as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds a custom function to Python.
Example
Var p As New MyPythonMBS

p.AddCustomFunction "Test"
p.AddCustomFunction "UserName"
p.AddCustomFunction "Sum"

Var r1 As Variant = p.Evaluate("Test('test')")
Var r2 As Variant = p.Evaluate("UserName()")
Var r3 As Variant = p.Evaluate("Sum(2,3,6)")

Break

You can define multiple functions all with different names.
Function names are case sensitive.

See also:

Some examples using this method:

PythonMBS.AddCustomFunction(FunctionName as String, theDelegate as CustomFunctionCalledMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds a custom function to call the delegate instead of the event.

See also:

PythonMBS.AddSysPath(Path as String)   New in 25.1

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 25.1 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Adds a file path to the system path list.

This allows you to add the path to the current virtual environment.

PythonMBS.Clear

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Clears the variables in the Python environment.
Example
Var p As New PythonMBS

p.Value("Hello") = 123.0
p.Clear

Var check As Boolean = p.HasValue("Hello")

Break

PythonMBS.Constructor

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
The constructor.

PythonMBS.DeleteValue(Key as String)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Deletes a variable in the Python environment.
Example
Var p As New PythonMBS

p.Value("Hello") = 123.0
p.DeleteValue "Hello"

Var check As Boolean = p.HasValue("Hello")

Break

PythonMBS.Evaluate(Expression as String) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Evaluates an expression in Python.
Example
Var p As New PythonMBS

Var r As Variant = p.Evaluate("1+2")
Print "Result: "+r

Break

Pass an expression to evaluate with Python.
Returns the result of the expression.

May raise a PythonExceptionMBS exception.

PythonMBS.HasValue(Key as String) as Boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Checks whether a variable is set for the Python environment.
Example
Var p As New PythonMBS

p.Value("Hello") = 123.0
Var hasIt As Boolean = p.HasValue("Hello")
Var hasNothing As Boolean = p.HasValue("other")

Break

Returns true if variable is set.

PythonMBS.Keys as Variant()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Queries the list of names for values.
Example
Var p As New MyPythonMBS

p.AddCustomFunction "Test"
p.Value("Other") = 123

For Each key As Variant In p.keys
Print "key: "+key
Next

Break

This includes the registered custom functions.

PythonMBS.Run(Script as String) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Runs a Python script.
Example
Var p As New MyPythonMBS

// calls print event
Call p.run("print('Hello')")

Pass the script text to run.
Returns the result of the script.

PythonMBS.RunFile(File as FolderItem) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Python MBS Python Plugin 24.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Runs a Python script file.

Returns the result of the script.

PythonMBS.Value(Key as String) as Variant

Type Topic Plugin Version macOS Windows Linux iOS Targets
property Python MBS Python Plugin 24.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Get or set a local variable in Python.
Example
Var p As New MyPythonMBS

p.Value("Hello") = 123.0
Var d As Double = p.Value("Hello")

break

Data types are converted as far as possible.
(Read and Write computed property)

The items on this page are in the following plugins: MBS Python Plugin.


The biggest plugin in space...