Load Materials from Material Library from Dynamo?

revit

#1

Is it possible from Dynamo to load Materials from the Material Library?

Thanks :wink:


#2

Hi Daniel,

Yes it is possible to get materials from the material library. See below screenshot and also you can set material using “Element.setMaterialParameterByCategory” node from Clockwork Package.

Material


#3

Daniel,

Did you by any chance mean loading materials into a Project Material Library from an External Material Library?

If that was your question, I am afraid there are no API methods exposed currently to do that. I found out that some people would create an Excel based material library with all of the properties needed to create a material and then instead of loading materials in they would create a new set of them in the project based on that Excel document. That is certainly something that we could do with Dynamo.

Good luck!


#4

@Konrad yes that was I wanted - from a external material library.

How can I create new ones from a excel file? That could be a solution!

Thanks :wink:


#5

Don’t hold be up to this, but you might be able to copy the materials from one project ( let’s say a company template with all materials pre-loaded) to your current project with the following method:

http://revitapisearch.com/html/b22df8f6-3fa3-e177-ffa5-ba6c639fb3dc.htm

I’ve never tried this personally.


#6

Thanks for the suggestion, but I am not (yet) skilled enough to know what to do with the codes :confused:

Anyone that knows how to handle the code in Dynamo?


#7

Dimitar,

Great idea! I can have a look at this and get back to you later.


#8
Daniel, I finally found some time to have a quick look at this issue, and it turns out that Dimitar was correct. Yes, you can use the CopyElements() method to copy all materials from one project to another. Here's what the full code would look like: # Copyright(c) 2015, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

# Import Element wrapper extension methods
import clr
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
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

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

import sys
pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN

RunIt = IN[1]

class CustomCopyHandler(IDuplicateTypeNamesHandler):
 def OnDuplicateTypeNamesFound(self, args):
 return DuplicateTypeAction.UseDestinationTypes

try:
 if RunIt:
 # Start Transaction
 TransactionManager.Instance.EnsureInTransaction(doc)
 
 errorReport = None
 fileDoc = app.OpenDocumentFile(IN[0])
 filter = ElementClassFilter(Material)
 allMat = FilteredElementCollector(fileDoc).WherePasses(filter).ToElementIds()
 trans = Autodesk.Revit.DB.Transform.Identity
 co = CopyPasteOptions()
 co.SetDuplicateTypeNamesHandler(CustomCopyHandler())
 
 newIds = ElementTransformUtils.CopyElements(fileDoc, allMat, doc, trans, co)
 
 output = []
 if newIds != None:
 for i in newIds:
 output.append(doc.GetElement(i).ToDSType(False))
 
 # End Transaction
 TransactionManager.Instance.TransactionTaskDone()
 else:
 errorReport = "Set Run it to true!"

except:
 # if error accurs anywhere in the process catch it
 import traceback
 errorReport = traceback.format_exc()

#Assign your output to the OUT variable
if errorReport == None:
 OUT = output
else:
 OUT = errorReport
```

#9

This forum is annoying but I can’t do anything about it so have fun re-typing it:


#10

Thanks Konrad! It works great! :slight_smile:

Here is the Dynamo file: https://www.dropbox.com/s/qz2ecq5a9o89oq2/loadMaterials_fromTemplateFilePath.dyn?dl=0

I was wondering if it were possible to add other Project Standards from selected file, like Object Styles etc? I tried to add a modified line after line 41 and replaced Material with Object Styles. That did not work. What would be the right line in this case?

Thanks,

daniel