Save Families from Revit to a Path

Quick question for the experts out there. Can Dynamo save queried Revit Families out to a specified path?

 

Thanks

1 Like

I guess that is a no then…

A very similar topic was already discussed here:

building up from that example, all you need to do is use the “SaveAs” method of the family document:

Here’s the code:

import clr

clr.AddReference('ProtoGeometry')

from Autodesk.DesignScript.Geometry import *



clr.AddReference('RevitAPI')

import Autodesk



clr.AddReference('RevitServices')

import RevitServices

from RevitServices.Persistence import DocumentManager

from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument



#Close all transactions

trans = TransactionManager.Instance

trans.ForceCloseTransaction()



fams = IN[0]

paths = IN[1]



#unwrap the Dynamo elements

fams = map(UnwrapElement, fams)



for i in xrange(len(fams) ):

    famDoc = doc.EditFamily(fams[i])

    famDoc.SaveAs(paths[i])

    famDoc.Close(False)

OUT = 0
4 Likes

Thanks for the response. I will check it out.

Ok. I was able to re-create the node structure and code blocks. Thanks again for that. I was also able to get it to run and save the Families out based on the Code Block “dir + “\family” + (1…Count(x)) + “.rfa”;”

The problem is that when they saved out, they were saved based on the naming the Code Block described (ie family1, family2, family3, etc.). I was hoping to maintain the name of the Family as it is loaded into the project. Any ideas on if there is a way to maintain that naming through the Code Block?

Hello Nick! Try this:

Thanks for the responses everyone. After a lot of help from a colleague at the office, this is where we ended up. Works great…

4 Likes

Hi Einar!

Thanks for your python script it works great.

Even though I am having a bit of trouble here.
I have two lists of families that I want to save, one of them is getting saved normally but the other one pops this error message.

Do you know what is happening?
Is it possible that Revit won’t allow me to save that kind of families?

Thanks

Not really sure but can you check if you have more than 1 (one) family? I got that kind of error when i am using python with a for loop that try to do to 1 item. Just maybe this is the reason…

Yes, I did it for the whole list and then I tried just with the first item.
Still the same unfortunately…

I think it might be because I have families in my list that can not be saved, like Rectangular Mullion.
Is there a way to filter out those families?

Hi @Einar_Raknes - I’m looking to do this for Groups, I know the famDoc portion of the code that @Dimitar_Venkov posted needs to be changed but not sure what to.

Can this be done? if so, I’m looking to be pointed in the right direction to make this happen.
Thanks,
Jason

@Jason_Trahan I’m not sure if its possible, you could try to contact Harry Mattison at BoostYourBIM:

1 Like

How do you get the dir name off the families when running?


I get an error when typing in this code? image image

Hi Anthony,

There seems to be a quirk where you aren’t (any longer?!) allowed to use “\” in a code block, if you put it in a String node instead it is allowed, perhaps someone more knowledgeable than me can explain why…

Cheers,

Mark

1 Like

That is the escape character In design script which says to ignore the special function of the next character. This allows you to use a quotation mark and other “command” characters in a string with a code block. An example (typing from memory so pardon any typos):

"1'-4""; will return an error.
"1'-4\""; will not.

To use \ you have to double it up as a result. Like so:

"Appdata\\roaming"

Thanks Jacob

Dear Nick,
Can you Please Share the Script here.
It would be Helpful to All of Us. Thanks In Advance.

@Nick_Bower Using the script above I am getting a weird error…Check it out below…I’m assuming it’s due to the fact that I’m using a different version Dynamo 1.2.2 but I don’t know for sure. LMK!

@erfajo I’m trying to learn Python to be able to understand what the code is doing. My question is where is a good place to troubleshoot errors that arise??

The code works for others but not me. Is that because I am using Dynamo 1.2.2. then what they’re using, and because of that changes to syntax give rise these errors?

Can you share your entire graph as an image? Zoom to read a node and use a camera export for this.