I have started a project with the goal of developing a dynamo script that will represent material types as different colours in the 3D active view.
For example ; Concrete=Red
I have started by writing a code in Python code that takes in that materials by name and assigns a colour, but I’m stuck on how to get from there back to a model in revit. Any help appreciated.
How would you go about doing this natively in Revit? I don’t think you can override material colors in view.
You can change the material appearance and cut pattern in Revit by going to the Manage tab, Settings panel, Materials and on the graphic’s tab change the colour of the patterns as required. What I’m trying to do is create a script ran through a python code that will override the material’s appearance and cut pattern when it is ran in revit.
This python script should do what you are after.
Just feed the node with element/s, view, filled pattern and rgb colors.
import clr #Import the Revit API clr.AddReference('RevitAPI') import Autodesk from Autodesk.Revit.DB import * #Import DocumentManager and TransactionManager clr.AddReference('RevitServices') import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager #Reference the active Document and application doc = DocumentManager.Instance.CurrentDBDocument #Start scripting here: #Get the solid fillpattern: fpe = FilteredElementCollector(doc).OfClass(FillPatternElement) solidPatternId = 0 for i in fpe: pattern = i.GetFillPattern() if pattern.IsSolidFill == True: solidPatternId = i.Id #### elems = [UnwrapElement(i) for i in IN] views = [UnwrapElement(i) for i in IN] rgb = IN pattern = IN output =  #Get the solid fillpattern: fpe = FilteredElementCollector(doc).OfClass(FillPatternElement) solidPatternId = 0 for i in fpe: pattern = i.GetFillPattern() if pattern.IsSolidFill == True: solidPatternId = i.Id #Create the color color = Autodesk.Revit.DB.Color(rgb,rgb,rgb) #Create the OverridesGraphicsSettings ogs = OverrideGraphicSettings() ogs.SetProjectionLineColor(color) ogs.SetCutBackgroundPatternColor(color) ogs.SetSurfaceBackgroundPatternColor(color) ogs.SetSurfaceForegroundPatternColor(color) ogs.SetCutBackgroundPatternVisible(False) ogs.SetHalftone(True) ogs.SetCutLineWeight(5) ogs.SetSurfaceForegroundPatternColor(color) ogs.SetSurfaceBackgroundPatternId(solidPatternId) #Transaction start: TransactionManager.Instance.EnsureInTransaction(doc) for i in views: for j in elems: output.append(i.SetElementOverrides(j.Id, ogs)) #Transaction end: TransactionManager.Instance.TransactionTaskDone() #Assign your output to the OUT variable. OUT = 0
This is overriding the entire element, not a single portion thereof, correct?
That’s correct. this script will override the graphic settings of the element/s in view.
I think the user is looking to change the appearance of just a portion thereof. Ie: make the concrete portion of the wall bright Red, but leave the rest as is.
Which unfortunately is not currently possible on a per view basis, but fortunately is on the roadmap for a future release: Trello
The material’s visibility settings could be updated temporarily, and then reverted back to what it was before; however that would be for all views in the model, and may have larger repercussions.
This is not a per-view override though, which seems to be what you’re asking for. The only view overrides are for the entire category or element. This is not currently possible in Revit.
You could, however, visualize the materials in Dynamo and assign colors there.
The script will override graphics rather than materis @C17495082EBFLG
If that is something that still interests you, please just feed the node with:
IN Rgb colors.
IN Filled Pattern
If i was to select create parts when an element is highlighted, that would create different layers of the subcomponents of an element, would I be able to feed in the materials then?
Yes; parts can be manually overridden by a material test.
That still wouldn’t map the material to any geometry. It would just give you a list of colors based on materials found in that element. Unless you’ve already broken down your element into material components representing geometry and this is just to map the material to a color.