Sunteți pe pagina 1din 1

Code blocks are extremely powerful in Dynamo.

Code blocks provide a bridge from visual


programming to text-based programming. DesignScript is the programming language, or syntax,
used by Dynamo. You can use DesignScript in a Code Block. But dont worry, you dont have to
know DesignScript to use Dynamo or even to use code blocks. You can start slow and work your
way up. To add a Code Block, you can simply double-click the canvas. Or, you can find it in the node
Library under Core > Input.Once a Code Block is placed on the canvas, you can enter code into
it. To begin, you can enter numerical values or text. To enter a numerical value, simply type a
number, such as 0. After you enter the number, click outside the Code Block on the canvas. When
you do, a semi-colon (;) is added after the number and an output port is available. The output is
0. You can click back in the Code Block to add additional code. Press ENTER and then type
2; Now when you click on the canvas, another output port is created. At this point, you have two
numerical values that can replace two Number nodes.Add another Code Block. In order to enter a
string, you need to add it inside double quotation marks (string). For example, if you needed to get
the Width parameter from a Revit element, you could enter Width into a Code Block to use for the
parameter name. And once again, a semi-colon is used to indicate the end of a line. You can also
enter formulas into code blocks. Add another Code Block and then type 3+4 into the code
field. After you do, you can see that the output is 7. You could also enter a+b and then you would
have an a input and a b input. This is useful when you have variables.Remember that the Dynamo
programming language is DesignScript. The nodes use this programming language as well. So you
can refer to nodes in a Code Block. For example, you can create a point with the
Point.ByCoordinates node, or you can use the syntax in a Code Block. To see this, add a Code
Block and then enter Point.ByCoordinates. As you type, you can see potential options. Before the
dot, these options refer to the available categories of nodes. After the dot, the options refer to the
actual nodes. You can use the arrow keys to select an option and press ENTER to add it to the
code. After Point.ByCoordinates, enter (1, 2, 3) to create a point at that coordinate location. It can
take some time to understand all the syntax. But you can start simple by using code blocks for
strings and numbers and work your way up.

S-ar putea să vă placă și