Skip to content

Custom Function Calls

maybites edited this page Nov 20, 2022 · 4 revisions

There are two ways to execute custom functions like this one:

custom_script
'''
functions used by message handlers
'''
import bpy
def my_function(address, args):
    
    print("my_function received :",address, args)

The easy and fast way

This is the recommended way, because the script is parsed only once and thus the execution is very efficient.

customScriptCall

where:

datapath: script(my_script).my_function

format: address, args

is referencing the text object called 'my_script' with the function called 'my_function', passing on the address and the arguments array.

The flexible way

This is the legacy way and should only be used if the above solution doesn't get you to the desired result.

custom_function_calls

where:

datapath: bpy.data.texts['my_script'].as_module().my_function('{0}',{1})

format: address, args

is referencing the text object called 'my_script' with the function called 'my_function', passing on the address and the arguments array.

Limitations

  • You need to enable Format and pass on a variable to the custom function.
  • You cannot use Loop.
  • You cannot send messages this way.

Clone this wiki locally