Is it possible from Dynamo to load Materials from the Material Library?
Thanks
Is it possible from Dynamo to load Materials from the Material Library?
Thanks
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.
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!
@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
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.
Thanks for the suggestion, but I am not (yet) skilled enough to know what to do with the codes
Anyone that knows how to handle the code in Dynamo?
Dimitar,
Great idea! I can have a look at this and get back to you later.
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
```
Thanks Konrad! It works great!
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