Using all parameters

hello all… i have a simple question for using built in blender functions…

I see people use function like playAction and only pass it a few parameters, like "playAction(“thisAction”, 1 2, 3, 4)

and code works fine as expected. But the playAction API lists it as having all these parameters:

playAction(name, start_frame, end_frame, layer=0, priority=0, blendin=0, play_mode=ACT_MODE_PLAY, layer_weight=0.0, ipo_flags=0, speed=1.0)

so that means in python/blender, if I only fill out say 5/10 parameters, it will just play the rest to some default value?

if I write function:

def function(parameter1, parameter2, parameter3 = 66, parameter4 = 17) I HAVE to insert a value for first two, but if I only pass it two elements, the other parameters will default to 66 and 17 and run as those numbers?

or if say I entered 1 item in… would parameter1 get that item, parameter2 would nto even exist, and then the other two would be the values 66 and 17?

sorry I know it basic, but I am learning. Thanks!

I believe the way it works is if there’s no default value listed in the API, for example, the name, start_frame, and end_frame in your example, its is required, but if there is a default listed and you don’t include it, it uses the default.

i see on API some functions like rayCast have parameters that can be “omitted” as well!

how to write function to do this though from scratch. Meaning, how do I achieve this in my own functions?

You would do it the same way:


def myFunction(a, b = ' World'):
    print(a+b)

myFunction('Hello')
>>>Hello World

myFunction('Hello', ' Everybody')
>>>Hello Everybody

yes okay I understand that, i mean for having variable that is not have default value, but can be instead omitted like rayCast function:

rayCast(objto, objfrom, dist, prop, face, xray, poly)

it has all these parameters, none having defaults, but I have seen it used with only objto and objfrom parameter entered and it worked fine??

maybe you looked at bpy’s ray_cast()?

Or maybe they are optional parameters after all, with default values of None.