Space Planning - Material.ByName and Elements not working

dynamo
revit
lunchbox
clockwork
excel

#1

Hi All,

I cant seem to figure out why my Material.ByName node output is null. The Element.SetParameterByName is also null. I tried matching the code block value to the excel sheet columns but still did not work.

Please help! Attached is a dropbox link to download the files! Thank You!


#2

I have something similar for space planning and remember running into a similar problem. The material creation needs to be accessed via a python node as it requires the api to create a new material for each element/department.

Attached is the sample dynamo nodes for the materials, hope it helps…

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 ToRevitColor(dynamoColor):
return Color(dynamoColor.Red, dynamoColor.Green, dynamoColor.Blue)

def ToDynamoObject(revitObject, isRevitOwned=False): # isRevitOwned should be False if Dynamo script created the object.
return revitObject.ToDSType(isRevitOwned)

doc = DocumentManager.Instance.CurrentDBDocument

names = IN[0]
transparencies = IN[1]
colors = IN[2]

newMaterials = []

for mat_name, transparency, color in zip(names, transparencies, colors):
TransactionManager.Instance.EnsureInTransaction(doc)
new_mat_id = Material.Create(doc, mat_name)
new_mat = doc.GetElement(new_mat_id)
new_mat.Color = ToRevitColor(color)
new_mat.Transparency = transparency
TransactionManager.Instance.TransactionTaskDone()
newMaterials.append(ToDynamoObject(new_mat))

OUT = newMaterials


#3

Another thing I noticed in the Mass Family is that I had to create and associate a parameter for the Fill Color material. It wasn’t there in the original download? Just double check to ensure you have the material parameter in the family associated with a parameter accessible in the project…this may be part of the problem?


#4

Thank You Scott, let me see if this helps! I am still a noob! I understood Rhino Grasshopper easily, however Dynamo seems a bit more complex.


#5

Hi Scott,

I guess the issue I am running into is the following. In Rhino-Grasshopper it is that you can set geometry from the actual 3D modeling program into the scripting plugin, and then manipulated it. Once you’re done, you can “bake” it back into the 3D modeling program and work with it there again.

I am sort of lost on what to do with the “generic box” created in the Revit family file. Also once the script is working, does dynamo have a “bake” option or can you start manipulating your shaped instantly in Revit?

Do you mind uploading you file?

Thanks!!


#6

okay so I figured out the Select Elements node lets you select the forms in the Revit into Dyanmo…but I still don’t know how to associate it with the fill color material


#7

It is a matter of gathering all of the elements in a list, and then once they are in a list they need to be assigned the corresponding material. It is all about the list management.
As for the Materials, the trick is to ensure that the value being fed into the Set parameter node is a material…that is where the Material.ByName node comes into play.
There is no “bake” function in Dynamo, so the script just does it’s thing…you can also set it into manual mode to gain a bit more control.
Hope this helps.


#8

Okay So I got most of it down. Still having a few issues with the Python Scripting. Can you take a look at what I have done, please? the Dynamo script added to the dropbox link above!


#9

It may also be that I am setting up the file wrong because I can not even get the masses to populate just the points.

  1. I loaded the Mass Family into a new Revit blank project.
  2. I set the family type in dynamo to that Mass Family
    3.Run the script- Issues with Material color and Element.SetParameterByName

lostttt -_-