Load multiple Families from a folder and to multiple Revit Models from a folder


#1

Hi All,

Time for asking questions…

I have multiple revit models (2017) and they are all in a folder and I also have families located on a folder.

What I want is simple enough (I think) but I am stuck. I want to load all families from a folder BUT to all Revit Models from a folder. I am not upgrading my families nor my revit models just simply loading families on different models, save and close each model with the loaded families.

I used this graph found in

and changed the DOC input to use Rhythm open document on background but it only do one at a time as I cannot figure out how to do a FOR EACH in the Document list and I also need to unwire everytime I need to save.

see below image and graph

have to do it one by one to work

dyn…
loadFamilyv2.dyn (10.7 KB)

thanks in advance…


Open, complete task, save, close
#2

Hi @4bimfercesp

Use @List levels for Document.BackGroundOpen if you have multiple lists.


#3

Hi kulkul

Thanks a lot, i dont follow you. There is a python code on this graph and only accept one doc at a time and it does not save. This is where i am stuck. Is there any OOTB can do this tasks?


#4

So modify the python to accept lists instead of individual elements? Or make it a custom node and try to work with lacing to get the right results?


#5

Yes i did this already…as each revit model is already opened (all in the folder) at the background it wont grab it (for each trick in python). Lacing does not work i tried that also. Due to same reason…i will retry it again maybe i missed something.


#6

List level is activated by the small arrows on the nodes.

accepting more than one element means that you need to implement a loop

one element =>
IN[0].element do something

several elements =>
for i in IN[0]
i.element do something


#7

I have tried to solve this problem, but has run into the “current document” problem. The attach graph load families in the current project… but if someone has an idea to code the node there can take loaded documents and make them active so Dynamo can work on them is it appreciated.

I have an idea that I need to change something in @john_pierson node “BackgroundOpen” or take its output and set it active somehow…

my graph so far…
ProjectLoadFamily.dyn (14.7 KB)

@4bimfercesp you could also try to see this solution by @Andreas_Dieckmann. He has made a solution for opening multiple files… maybe it could be combined with my LoadFamily.


#8

DynamoAutomation unfortunately does not perform reliably on top of Revit 2017.
For Revit 2016, this would indeed work.


#9

As far as I understand @Andreas_Dieckmann, it isnt possible to change the “current project” except if you open a new session…

Meaning using the OpenAndActivateDocument method or something similar.
http://www.revitapidocs.com/2015/3b3d671d-47ec-2ed8-1818-a7c19d01884b.htm
I have an idea that is what you have done in your DynamoAutomation.

If that is the case, then I would suggest you @4bimfercesp to open the projects manually and then run LoadFamily. If @Andreas_Dieckmann manage to get DynamoAutomation going for 2017 and 2018, then try combining these solution :slight_smile:

You can take my previous graph and remove before and after the red block :slight_smile:


#10

@erfajo many thanks for your efforts, I will do as you suggested just open the documents and apply your original solution and be done with it.

thanks to all.


#11

Your are welcome, but I somehow hope that @Andreas_Dieckmann will get his DynamoAutomation going for 2017 and 2018 or the dynamoteam will provide a solution for setting the current document.


#12

@erfajo, it seems like you can open and activate. http://www.revitapidocs.com/2018/3b3d671d-47ec-2ed8-1818-a7c19d01884b.htm


#13

@john_pierson, I actually tried but it rejected to take string as a input even though it should be able to take the file as sting. It might be something with casting it to a document type.

…But I ended up thinking that I used to much time on this issue if the user just by opening the files could solve it and then load the families. It is never the less a challenging issue and I will try to look further into it. It would however fit into your package as an extra option for your BackgroundOpen node (a new ForegroundOpen) :wink:


#14

@4bimfercesp This is probably not the political correct answer here on the Dynamo forums, but it is quite easy to achieve with an application macro in Revit. Run it without any documents open i Revit.

	public void BatchAddFamilies()
	{	
		string[] files = {@"C:\Users\eibre\Desktop\revit\opendoc\RIB.rvt", @"C:\Users\eibre\Desktop\revit\opendoc\ark.rvt"};
		string[] famFiles = {@"C:\Users\eibre\Desktop\revit\opendoc\hexagon.rfa",@"C:\Users\eibre\Desktop\revit\opendoc\triangle.rfa"};
		foreach (string file1 in files) {
			Document doc1 = Application.OpenDocumentFile(file1);
			Transaction t1 = new Transaction(doc1,"Load family");
			t1.Start();
			foreach(string famFile in famFiles) {
				doc1.LoadFamily(famFile);
			}
			t1.Commit();
			doc1.Close();
		}
	}

Reload Family and overwrite parameter values
#15

Thanks a lot i will try this…it looks really simple i used to do a lot of macro with revit. But now my attention is with dynamo as i can involve none revit programmers as dynamo is more visual which everyone can easily grasp than macro although some may say its the opposite. Thanks again i have now both macro and dynamo to use in order to solve my open document background or multiple open revit and run tasks on it. I know it may not be possible but its fun otherwise. Thanks


#16

Hi All,
Finally broke the Code…I can now open and load families or even run tasks on multiple revit models. Just want to share the great news.

Will be posting the code in the coming days just making sure it is working 100% before I share. Special thanks to @Einar_Raknes and @erfajo who helped me figure it out.

Let the good times roll…also thanks to @Konrad_K_Sobon and @Daniel_Woodcock1 for sharing their python code which enables me to come up with the workflow.

watch the space…
thanks again to the community.


#17

sorry for answering so late… but the syntax is not correct in your post according to the API.
I used also the wrong syntax until recently :slight_smile:

This is the correct use in the post
http://www.revitapidocs.com/2018/6a91dc8e-6c2b-52b9-dfc4-d56fa472852b.htm
public Family LoadFamily( Document targetDocument )

If present families must be overwritten, then use this syntax.
http://www.revitapidocs.com/2018/cb950c8e-f440-c6db-8563-d1dd16ef3fee.htm
public Family LoadFamily( Document targetDocument, IFamilyLoadOptions familyLoadOptions )

For updated code for family loading please see here.


#18

@erfajo Do you mean that doc1.LoadFamily(famFile) should be famFile.LoadFamily(doc1) ?


#19

yes… exactly :slight_smile:
try to see Jeremy Tammik


#20

@erfajo FYI: There’s a new DynamoAutomation version out now that is compatible with Revit 2017 & 2018.