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.
It was one of the firsts post I followed,
the thing is I would like to set the properties in the Identity tab first (Descriptive Information and Product Information), .
From the Graphics Tab check the ‘use render appereance’ checkbox,
the Appereance Tab name and comments , the image can be/should be managed manually.
Trying to break through some mysteries here, I discovered some interesting things. I am on R2017 at the moment:
First, the color of a material (the one from the Graphics tab) can be set with a simple Element.SetParameterByName node. The awaited value is an integer but I don’t know how this number is defined. I have been able to set a value from 0 up to 16777215.
Second, the whole Appearance tab can be set by switching the material asset element with Material.SetMaterialAssetByAssetId or Material.SetMaterialAssetByMaterial from Archi-lab_Grimshaw, but I assume that this has already been exposed somewhere.
Afraid not. It was just from experimenting with integers and the resulting RGB values.
Here’s how it breaks down:
Red takes up integers 0-255. Makes sense.
Green starts at 256 but begins counting with the Red values. So 256 = [R=0,G=1,B=0] and 257 = [R=1,G=1,B=0] and so on.
Blue starts at 65536 and follows the same pattern of counting the Red value first, followed by Green, then finally Blue.
Sorry for late response, but I’ve abandoned the idea of doing this with python and switched to c#. With VS you can connect directly to RevitSDK and contextual help there works very well.
I have created few project parameters by “Parameter.CreateProjectParameter” for the category “Materials”. now I’m trying to set these parameter values and I cant achieve it through “Element.SetPararmeterByName”.
You’re feeding the parameter a string, and it wants something else (not sure what as I don’t see where you made the parameter here). Try a double or integer, if that fails start a new topic and include your graph and a sample rvt file.
Thanks Jacob. You were right. I was setting these new parameters type to “Number” and that’s why it was not taking input of a “String”. Now I have the parameter type to “Text” and it takes input from both numbers and strings.