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


#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.


#21

Hi Andreas,

Thanks for the update, however I did not used the Dynamo Automation to solve my topic. I have made a different approach on the loading multiple families from a folder and load them to multiple Revit models.

Thanks again for your hard work.


#22

Hi @4bimfercesp
Were you able to find a solution to this?

I was trying something like the below. I am trying to piece together python - this doesn’t work at the moment.
Any suggestions?


"
import clr
clr.AddReference(‘ProtoGeometry’)
import Autodesk.DesignScript as AD
from Autodesk.DesignScript.Geometry import *

clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

#input assigned the IN variables
paths = IN[0]
docs = IN[1]

#wrap input inside a list (if not a list)
if not isinstance(paths, list): paths = [paths]

#ensure loaded families can overwrite existing families.
class FamilyOption(IFamilyLoadOptions):
def OnFamilyFound(self, familyInUse, overwriteParameterValues):
overwriteParameterValues = True
return True

def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
	source = FamilySource.Family
	overwriteParameterValues = True
	return True

for doc in docs :
TransactionManager.Instance.EnsureInTransaction(doc)

#core data processing
for path in paths:
try:
famDoc = app.OpenDocumentFile(path)
famDoc.LoadFamily(doc, FamilyOption())
famDoc.Close(False)
except:
pass

TransactionManager.Instance.ForceCloseTransaction()

#output assigned the OUT variable
OUT = paths, docs
";



#23

I have a simple node that solves this problem. please share
I use the node “LoadFamily (document, family) of the Orchid package”
p / s: Please select Lacing - longest


22
Link:https://awaygroup-my.sharepoint.com/:u:/g/personal/quoc_nguyen_draftaway_com_au/EXuJ6J5ivhBGqwx4x9corlYBPtA_-2fRyUrEo35aZdtlgA?e=FhKAI2


#24

@quoc.nguyen, please dont release it this way. do only share what you have control over, namely your graph files. You can give the link to my package at github, instead of zipping it and sharing it at some cloud service. Very soon is this zip file outdated. I am going to release an update within few days.


#25

@erfajo, Sorry, I edited the post


#26

good… I have also in the meantime updated my package with more new nodes (for system families)