Hi everyone, I’m a newcomer to the Bim/Revit/Dynamo world, so please excuse my ingenuity beforehand.
My new task is to prepare about 5000 materials, which are pretty similar one to another.
After a few days creating everything manually, decided give Dynamo a chance to do that for me.
Did my (quick) research on internets, found the script for creating materials with python, modified it to suit my needs.
It creates the materials in revit, but I can’t find the way to set material properties from within it,
gives me following error "TypeError: 'ParameterSet' object is unsubscriptable"
Here’s the script:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
def ToDynamoObject(revitObject, isRevitOwned=False):
# isRevitOwned should be False if Dynamo script created the object.
return revitObject.ToDSType(isRevitOwned)
doc = DocumentManager.Instance.CurrentDBDocument
#Las entradas de este nodo se almacenan como lista en las variables IN.
dataEnteringNode = IN
#Asigne la salida a la variable OUT.
OUT = 0
newMaterials = []
for mat_list in dataEnteringNode:
for id, fmt, gr, din, mat_name, aspect_name, comments, url in mat_list:
TransactionManager.Instance.EnsureInTransaction(doc)
mat_name_r = mat_name.replace('"','')
mat_name_t = mat_name_r.strip()
new_mat_id = Material.Create(doc, mat_name_t)
new_mat = doc.GetElement(new_mat_id)
#new_mat.MaterialClass("Wood")
#new_mat.Transparency = transparency
#new_mat.URL = url
new_mat.Parameters['URL'] = url
#elem = UnwrapElement(new_mat)
#elem.Parameters['URL'] = url
TransactionManager.Instance.TransactionTaskDone()
#newMaterials.append(ToDynamoObject(new_mat))
newMaterials.append(new_mat)
#newMaterials.append(ToDynamoObject(new_mat.Properties))
OUT = newMaterials
As you can see, I’ve tried a few possibilities, but none of them worked.
Or setting material properties member is similar to following snippet (found here: modify-the-material-thermalconductivity-parameter) :
thermalAssetID = material.ThermalAssetId
propertySetElement = doc.GetElement(thermalAssetID)
thermalass = propertySetElement.GetThermalAsset()
thermalass.ThermalConductivity = thermalcond
Any link (to) manual, tutorial or a few lines of code will by highly appreciated.