From the course: Dynamo for Revit: Python Scripting

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Defining functions

Defining functions

From the course: Dynamo for Revit: Python Scripting

Start my 1-month free trial

Defining functions

- [Instructor] In an earlier class, we learned how to use a range of numbers by using the range function. We can also create our own functions if we find that we are reusing the same piece of script over and over. So, let's try creating our own function in Python. In a new Dynamo file, go ahead and place a new Python Script node. To understand functions, let's start with something simple, a function that simply returns a number. To create the function, we start with the keyword def, which is short for define, followed by a unique name so it doesn't conflict with any other names in Python. Let's call it MyFunction. We then put a set of parentheses. Between these parentheses we can put parameters for the function, but let's keep this one simple, so we'll just use an open and close parentheses followed by a colon as it's a statement. Any code that we want to be part of this function needs to be written with the indented space after the colon. The same in statements like if, else, or a…

Contents