Join Paul F. Aubin for an in-depth discussion in this video Renaming families with Dynamo, part of Revit: Tips, Tricks, and Troubleshooting.
- In this tip I want to talk about how you can use Dynamo to rename a bunch of families. Now, I was working on this recently, and I happened to stumble on this blog post from a friend of mine who runs a company called EvolveLAB. So Bill posted this blog post here back in March, and it was exactly the same idea, so I thought well, that's great, I'll just show Bill's post here. So as you can see, he's got the graph all scripted out here, and some details on what each of the nodes are. And this is essentially the same graph that I'm gonna build with you here right now, so you can read through the post if you like, or you can just follow along with me here directly.
But, you know, I contacted Bill, and I said, "Hey, great minds think alike. "We're both trying to use Dynamo to do some batch renaming." So let's talk about the goal here, so you know, I've got this file open, and I've got several items in this file that are using an LDC prefix, you can see it here. And I've decided that I no longer want that LDC prefix, I want to change it to something else. I could certainly select these things one at a time, and right-click and go to rename, and then, you know, edit what I want to edit.
But that would obviously be very tedious, especially when you consider that there might be dozens or even hundreds of these items to do that to. So certainly having something a little more automated would be preferable. Any time you have a task that is gonna do the same thing over and over again, on lots of stuff, you should always be thinking that maybe Dynamo is a good solution for that. So on the Manage tab here, I'm gonna click the Dynamo button to launch Dynamo. I'm gonna click New, and just kind of build this graph from scratch, because it's actually a fairly simple graph.
So this way you can kind of see all of the steps. So I'm gonna start with out-of-the box nodes here, I'm gonna start on the Revit branch, and under selection, I'm gonna choose the Element Types node. Now the Element Types node just gives us a drop-down list, and from this list, you can choose what kind of element you're looking for. I'm gonna type the letter F to jump down to the Fs in the alphabetical list here, and then choose Family. Now, right above Element Types, we have All Elements of Type.
Now what that means is, this is focusing us on families, but then when we wire this to this second one, it says select all of them. Okay, so it's going to build a list of all of the families. So that's our initial selection. Now what are we going to do with that selection? Well, the next thing that I wanna do is limit the selection not to every single family in the file, but I want to limit the selection to only those that start with the letters LDC.
So that means that, you know, if we go into Core here, I'm going to need a string. So I'm going to Input, and choose a String. And it's actually _LDC that I'm looking for. So that's what I want to search for. And now I need a node that's going to allow me to search for that. Now if we look underneath the Text nodes. Text is actually string in programming terminology, so we're gonna look under the String nodes. We're looking for one that says "string contains," so here we've got String.Contains, and it's got three inputs.
Now I've already got this one, which is what do I want to search for. IgnoreCase is a Boolean, and if you would like to be able to type it in as lowercase LDC or uppercase LDC, then you can feed the Boolean in, but by default, that's actually set to false, which means it's kind of like a double negative. But it means that it will not ignore the case, therefore the case matters. Okay, so I'm gonna leave it set to that. But then, this is looking for a string. So if I tried to feed elements into the string, it's gonna fail, okay? So what I need to do is take this list of elements, and convert them to text.
So I can do that with a String from Object node. And I'll find that right there, okay? So I'll select String from Object. Let me just move these two out of the way, kind of fit this one in between. And do it like so. Now, my little reveal bubble here tells me all of these different values, and notice that the output from here comes out as a Boolean. So that means that all of these values are coming out as either false or true.
So notice, some of them are true, some of them are false. So in other words, think of this as like, you're asking that list, "Do you contain the letters LDC?" And if it does, then it says True. Otherwise it says False. Now what can we do with that? Well, we've got a node called FilterByBoolMask, which is sort of a funny little name, and I'm gonna type that in here. I'm gonna type in filter. And you see how that comes right up at the top. So FilterByBoolMask, what this means is, it's gonna take a list of Booleans, a list of trues and falses, and then it's gonna separate that out into two separate lists.
It's gonna put all the trues in one list and all the falses in another. So, you come back to the original list of elements, and you feed that in as your list. And then your mask is your list of Booleans, okay? Then what I'm gonna do is add a Watch node, so that we can see what's coming out of this node here. And put it right there. And notice now that I've got 14 families that it found that start with the letters LDC, or that contain the letters LDC.
So from this original list here, which had 133 items, there's only 14 of them that make the cut. So those are the 14 items that we want to work on. So we're going to take those to the next step in the graph. Okay, so let me clear out my search here. What I wanna put in next is Name. And I'm looking for Element.Name. Element.Name. So it's this one right here. So this is gonna ask for a list of elements, and then it's just gonna come out on the other end as a string with those names.
So the only ones that I care about in this case are the ones coming out of the in port of the BoolMask. So it's really the same list of 14 items, but notice that the difference here in the Watch node, this says family: and then the name. This just says the name. So really what that did was it just stripped off the fact that those were family elements, and it just limited it to just the names. All we care about is the names now. And it's outputting those as strings.
Okay, so, that's good. Now what are we gonna do? Well, now we're gonna go back to our String nodes here, and we want to find a Replace. So, with the String node, you feed in some strings, and then you're gonna input what you want to search for, and what you want to replace it with. So I'll just borrow this string right here, since it's already what I want to search for. Control + C, Control + V, paste that over here. Let me Control + V again.
And what I'm gonna substitute these with is a new prefix, LIL. So I want to search for LDC, and I want to replace it with LIL. And let's borrow this Watch. Control + C, Control + V. And let's put that right there, and now you can see all of those names have been changed. So now I have those names, but it's just in a list in Dynamo. If I move this out of the way, here in the background, you can see that the families in Revit are still named LDC.
So now I need something that's going to take these names, and pump them back into Revit and update all of those families. So this one, you're gonna need a Package node for. So if I kind of collapse these down, it's under Clockwork, now if you don't have Clockwork. Go to Packages, search for a package, wait for this thing to load, and then come up here and type "clockwork." Make sure you're installing the latest version, and then it will install it on your system, and you'll get a new Clockwork branch here in your library.
So now if I search for the Clockwork node, which is gonna be Element.SetName, so I'm just gonna type in setname here, this SetName is setting the names of room elements in Revit, that's not the one we want. We want this one: Element.SetName. And that's part of the Clockwork package. So I'll go ahead and bring this one in, and I'm gonna go back to our original list of elements that are coming out of our BoolMask, right here. And I'm gonna feed that list of elements into the element port here.
Then I'm gonna take this list of names from the String.Replace, now remember, these are the ones that we replaced, this list that you're seeing right here. And I want you to watch here in the background as I feed this string into the name field right here. And you'll see, all of those families just updated to match that new naming convention. Now if you want, you can add another Watch node right here. To the end.
And see if anything failed. That says Empty List, which is generally a good thing. Now, if I click over here into Revit, and I scroll down, these are my annotation symbols, and a little bit further down, I have some Casework items. Here's some detail elements. What do all those things have in common? Well those are all loadable families. Generic models, okay, but if I go down a little bit further, here's a basic roof, and it still says LDC. Here's some basic walls, and they still say LDC.
So when we go all the way back to the beginning of this graph here, what you have to keep in mind is that the element type of family really means loadable family. So it captured most of the stuff that had the names that we were looking for, but now you might need to go through this drop list and change it to a few other things. In order to capture all that other stuff. So if I open up the list here, and I scroll down toward the bottom, what I could look for here is WallType.
So if I change it to WallType, and you watch it in the background, because I'm set to automatic execution, it'll run it immediately. So you might need to go through and do this a couple times, you know, you could do RoofType and you could do WallType, but if you really want to capture everything, it might take a few passes. But it's still gonna be much faster than if you had to edit all of those manually.
NOTE: The exercise files for this course can only be opened in the most recent version of Revit (Revit 2017).
Skill Level Appropriate for all
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.