Dynamo's node library performs actions on all kinds of data, not just numbers. This video is focused around the "string" data type, which is the computer science term for "text", or "a string of characters". Once we've created our first string, we'll cover some commonly used nodes that take string data as an input.
- [Voiceover] Now let's focus on Dynamo's string data type, which is the computer science term for text or a string of characters. Once we've created our first string, we'll cover some commonly used nodes that use string data as an input. In architectural engineering in construction workflows, strings are frequently used in similar ways to a text parameter on Revit. Maybe it'll be a mark or a key value or some other identifier for objects or data, and sometimes they're used as notes or complete sentences. Let's begin this example by dropping in a string input, which we can find in the core input section of the node library.
Let's go ahead and click on the gray box inside the string node and give it a value. Now most of the nodes that we'll use in this video will perform functions on strings that they take as an input, and they'll come from the core string section of the node library. Let's begin with the ChangeCase node. This node takes two inputs: the string, which we already have in our workspace, so we'll go ahead and plug that one in, and it also takes a boolean value for upper. If we read the node description, it's basically asking, "Would you like to "convert all of the characters in this string to uppercase?" If so, then select true.
Otherwise, false would mean lowercase. So we're also going to need to drop in a boolean input as well. If your office has a drawing standard that requires text to be typed in uppercase, this node can be an excellent way to make sure that any text output from your Dynamo graph adheres to that standard. Let's drop in a boolean input node in our workspace to plug into the upper input. Now rather than browsing the node library for the boolean input, I'm gonna click on the white search bar at the top of the library pane, and I'm gonna type "boolean." This is a much faster way to find nodes if you already have an idea of what their name is.
I'll drop in the boolean node, and then I'll click the X button in the search bar. It'll take me right back to where I was in the node library. Let's go ahead and plug that boolean into the upper input of ChangeCase. When we look at the node preview, you'll notice that the output is entirely in lowercase. Now if I switch the boolean value from false to true, you'll notice that the entire string is translated to uppercase instead. Now again, this could be a great technique to automatically change all of your drawing numbers and drawing titles to uppercase in case people on your project team aren't following your company standards.
See, now our drawing number and our drawing title are all written in uppercase letters. I'm gonna go ahead and undo that change by clicking edit, undo, or I could use the classic control Z as the keyboard shortcut. Now, let's drop in the replace node. This node behaves a lot like the find and replace feature in Microsoft Word. It looks for all the times that a specific string of text occurs in a string input, and it replaces them with another string that we specify. Maybe you'll use this node as part of a script that you're writing that finds all the times that you type "steel" in the text notes of a drawing and replaces them with something like "aluminum." It can also be helpful in making sure that your project is abiding by your firm's CAD or BIM standards.
Maybe you need to replace all the spaces in your Revit view names with underscores. Let's use that as an example. We'll take our input string, which is, "This is a string," and we'll plug it into our string input. Next, we need to specify the text that needs to be replaced or the SearchFor input. Let's make a copy of our string input and change the input text to a single space using the space bar. We're gonna select our string input, control C, and control V to copy another instance. I'm also going to change the text that we're inputting.
Instead of, "This is a string," I'm going to hit the space bar key one time. Again, this is not a blank input. There actually is a space there that I just created by hitting the space bar. I'll plug that into our SearchFor. Now, our final input is ReplaceWith. The node's currently going to look at the input string, find all of the spaces according to our SearchFor, and we wanna replace it with, in this example, an underscore. I'll copy our string input one more time, and here, I'll type an underscore instead of a space, and I'll plug that into ReplaceWith.
If we look at our node preview, you'll notice that we now see, "This is a string," but instead of the spaces, we see an underscore. Now again, if it's your firm's standards to type this entirely in uppercase, we can just go ahead and plug the output into our StringChangeCase. Now, you'll notice, "This is a string," with underscores and all capital letters. Now let's drop in a similar node called CountOccurrences. Maybe you've used this node before running the string replace in order to identify exactly how many instances you're about to change.
Let's count how many spaces occur in the input string, "This is a string." We'll go ahead and plug that into our first input. You'll notice that this node also takes a SearchFor input. So we'll search for all the spaces in that first input string. Our third input is IgnoreCase. If we hover over that, we can see that it's asking for a boolean. Do we take the case of the input into account? In this case, we're looking for spaces, so this isn't really related to us. We'll leave it as the default value of false.
You'll also notice in our node preview that the number three is our output, which means there are three spaces in the, "This is a string," input. That makes sense because that's exactly how many underscores we ended up with. Now, for a simpler example, let's look at the length node. I'm going to zoom out a little bit here and zoom back in. The length node simply counts the number of characters that are in a string, just like Twitter gives you a live preview of how many characters are in the Tweet you're about to send so you can keep it under 140. If we plug in our input string to the input of string length you'll notice that the output is a simple number, in this case 17, which is exactly how many characters are in our, "This is a string." input text.
Now let's look at one more example called "split." This node takes the same string input that we've seen in the other examples as well as a string input called "separator." The idea of this node is to find all of the places where this separator string occurs very similar to replace or CountOccurrences, but then it uses that substring as a way to generate a list of strings. Let's plug in our space string input as the separator and see what comes out on the other side. So as you can see, each word became its own item in a list of strings.
Now in another video, we saw how we can use just one or two nodes to quickly generate a list of numbers. This is roughly the equivalent for generating a list of strings. This can also be very useful if you're importing text format data into Dynamo that's extremely well-organized, maybe data that uses commas or semicolons to separate clusters of related information. I'm thinking specifically of CSV or comma-separated values format, or maybe you need to import a list of email addresses from an address book that uses the less than and the greater than symbols to denote an address or a hyperlink.
So as you can see, Dynamo isn't just for numbers. It can be quite powerful in analyzing and modifying the text data in your projects and your building information models.
- Placing and connecting Dynamo nodes
- Understanding Dynamo's data types
- Performing math functions
- Creating number lists and text strings
- Writing data to an Excel spreadsheet
- Creating points, curves, surfaces, and solids
- Analyzing geometry
- Linking a Dynamo-driven SAT into Revit
- Placing Revit families with Dynamo
- Creating Revit views and sheets with Dynamo