& Construction

Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
& Manufacturing

Professional CAD/CAM tools built on Inventor and AutoCAD
Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
Professional CAD/CAM tools built on Inventor and AutoCAD
Create reusable code modules to perform repeatable tasks with inputs and outputs using the Functions blocks in the Informed Design Codeblocks Editor.
Type:
Tutorial
Length:
5 min.
Transcript
00:00
The Function code blocks include two primary Function block types,
00:07
as well as a Function Conditional block.
00:11
Functions are self-contained modules of code that are set up to accomplish a specific task.
00:18
Functions are called from another Calling block and run on demand when called.
00:23
Often a function is handed data from the Calling block,
00:27
at the time that it is called.
00:29
The function can be called throughout the rule as many times as needed.
00:34
It can even be handed different data each time it is called.
00:38
Here, we will create a function to set the area parameter value.
00:43
First, the block is added to the canvas, and then the name of the function is typed in.
00:49
Upon adding the function, the Calling block is automatically created and added to the Functions blocks.
00:56
The Calling block is added to the canvas at the point from which it is to be called.
01:01
Next, the plus sign is clicked in the function to add a variable.
01:06
This variable is automatically added to the Calling block as well,
01:10
in effect, wiring up the connection between the two blocks.
01:15
Using the plus sign again, a second variable is added.
01:18
Then, the Parameters are plugged into the Calling block
01:22
so that the values are passed to the function using the variables as the means with which to do so.
01:29
Then, the Area Parameter is added to the function,
01:33
and a Math block is snapped to it,
01:35
providing the place to do the calculation of the data that is to be passed into the function when it is called.
01:43
Looking in the Variables, we find that our variable blocks have been automatically created there for us.
01:49
Adding them to the Math block, within the function is all we need to do to complete the function to set the area value.
01:58
Testing with the form shows that the area value updates as expected
02:02
and that our function works as designed.
02:05
Next, we'll add another function using the other available Function code block type, which returns an output.
02:14
First, we Collapse the existing Function blocks to make space in the canvas.
02:19
Next, the block is added to the canvas, and then the name of the function is typed in.
02:25
The Calling block, which was created for us automatically, is added to the Canvas as well.
02:31
This type of Function block expects a Parameter to call the function and receive the function output.
02:38
So, one is selected and joined to the Calling block.
02:41
Next, the plus sign is clicked in the function to add variables.
02:46
Recall, these variables are automatically added to the Calling block as well,
02:51
providing the data connections between the two blocks.
02:54
A new variable is created to provide a container for the information that will be assembled before passing it back up to the Calling block.
03:04
The variable is placed in the function,
03:07
and then a Text block is added to concatenate the label string passed in from the parameter,
03:12
a static string and a calculated value, that converts the passed in parameter value from feet to inches.
03:20
The Create Text With block can be expanded to add as many lines as needed to build the string just as you prefer to see it.
03:28
In this case, we will use this string as the tooltip message in the form
03:33
to provide our user a quick way to see the parameter value in an alternate unit.
03:39
Then, we'll add the Container Variable to be returned from the function back up to the Calling block.
03:46
And then finally, we add the Parameters to the Calling block to pass the information to our completed function,
03:54
ensuring it has the data type it expects.
03:58
A quick test in the form, and we see that it works.
04:03
Duplicating the Calling block and updating the new instance to use the Height parameter rather than the Length,
04:10
is all that is needed to reuse our function.
04:13
A quick snap to tidy up, and then we can test some values in the form
04:19
to ensure that our function is serving up the feet to inches conversion
04:23
for both parameters that are calling it.
04:29
In summary, functions are self-contained, reusable modules of code that we set up to accomplish a task.
04:39
Functions are called from a Calling block and run on demand when called.
04:44
Functions are often handed data from the Calling block to perform the task they were created to do.
Video transcript
00:00
The Function code blocks include two primary Function block types,
00:07
as well as a Function Conditional block.
00:11
Functions are self-contained modules of code that are set up to accomplish a specific task.
00:18
Functions are called from another Calling block and run on demand when called.
00:23
Often a function is handed data from the Calling block,
00:27
at the time that it is called.
00:29
The function can be called throughout the rule as many times as needed.
00:34
It can even be handed different data each time it is called.
00:38
Here, we will create a function to set the area parameter value.
00:43
First, the block is added to the canvas, and then the name of the function is typed in.
00:49
Upon adding the function, the Calling block is automatically created and added to the Functions blocks.
00:56
The Calling block is added to the canvas at the point from which it is to be called.
01:01
Next, the plus sign is clicked in the function to add a variable.
01:06
This variable is automatically added to the Calling block as well,
01:10
in effect, wiring up the connection between the two blocks.
01:15
Using the plus sign again, a second variable is added.
01:18
Then, the Parameters are plugged into the Calling block
01:22
so that the values are passed to the function using the variables as the means with which to do so.
01:29
Then, the Area Parameter is added to the function,
01:33
and a Math block is snapped to it,
01:35
providing the place to do the calculation of the data that is to be passed into the function when it is called.
01:43
Looking in the Variables, we find that our variable blocks have been automatically created there for us.
01:49
Adding them to the Math block, within the function is all we need to do to complete the function to set the area value.
01:58
Testing with the form shows that the area value updates as expected
02:02
and that our function works as designed.
02:05
Next, we'll add another function using the other available Function code block type, which returns an output.
02:14
First, we Collapse the existing Function blocks to make space in the canvas.
02:19
Next, the block is added to the canvas, and then the name of the function is typed in.
02:25
The Calling block, which was created for us automatically, is added to the Canvas as well.
02:31
This type of Function block expects a Parameter to call the function and receive the function output.
02:38
So, one is selected and joined to the Calling block.
02:41
Next, the plus sign is clicked in the function to add variables.
02:46
Recall, these variables are automatically added to the Calling block as well,
02:51
providing the data connections between the two blocks.
02:54
A new variable is created to provide a container for the information that will be assembled before passing it back up to the Calling block.
03:04
The variable is placed in the function,
03:07
and then a Text block is added to concatenate the label string passed in from the parameter,
03:12
a static string and a calculated value, that converts the passed in parameter value from feet to inches.
03:20
The Create Text With block can be expanded to add as many lines as needed to build the string just as you prefer to see it.
03:28
In this case, we will use this string as the tooltip message in the form
03:33
to provide our user a quick way to see the parameter value in an alternate unit.
03:39
Then, we'll add the Container Variable to be returned from the function back up to the Calling block.
03:46
And then finally, we add the Parameters to the Calling block to pass the information to our completed function,
03:54
ensuring it has the data type it expects.
03:58
A quick test in the form, and we see that it works.
04:03
Duplicating the Calling block and updating the new instance to use the Height parameter rather than the Length,
04:10
is all that is needed to reuse our function.
04:13
A quick snap to tidy up, and then we can test some values in the form
04:19
to ensure that our function is serving up the feet to inches conversion
04:23
for both parameters that are calling it.
04:29
In summary, functions are self-contained, reusable modules of code that we set up to accomplish a task.
04:39
Functions are called from a Calling block and run on demand when called.
04:44
Functions are often handed data from the Calling block to perform the task they were created to do.
The Function code blocks include two primary Function block types, as well as a Function Conditional block. Functions are self-contained modules of code that are set up to accomplish a specific task. Functions are called on demand from a Calling block. When called, a function is often given data from the Calling block to perform the specified task. The function can be called throughout the rule as many times as needed. It can even be given different data each time it is called.
In this example, create a function to calculate an area parameter value.
When a Function block is added to the canvas, a Calling block is automatically created and added to the Functions library.
This variable is automatically added to the Calling block as well; in effect, connecting the two blocks.
The Length and Height values will be passed to the Function through the variables.
Next, create a function using the Function Return block, which is set to return an output.
This type of Function block expects a parameter to call the Function and receive the Function output.
Note that these variables are automatically added to the Calling block.
This adds a new variable that acts as a container for the Function information before passing it to the Calling block.
Set the Create Text With block to display a form message with the Length in inches.
To create the same message for the Height parameter:
In summary, functions are self-contained, reusable modules of code that are set up to accomplish a task. Functions are called from a Calling block and run on demand when called. Functions are often given data from the Calling block to perform the specified task.
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Sign in for the best experience
Save your progress
Get access to courses
Receive personalized recommendations
May we collect and use your data?
Learn more about the Third Party Services we use and our Privacy Statement.May we collect and use your data to tailor your experience?
Explore the benefits of a customized experience by managing your privacy settings for this site or visit our Privacy Statement to learn more about your options.