Dynamo script for transferring material color codes into graphic overrides

Translated by moderator. See below the line for original post.


Hello everyone,

I’d like to create a Dynamo script that automatically reads the material color codes of the pipe system types and then applies these colors to the graphical overrides of the line colors. Pipe system types with the same material color code should automatically receive the same line color in the graphical overrides.

The goal is to keep the color definitions consistent and reduce the manual effort required to maintain the graphical representation.

Specifically, the script should: read the material color codes of the pipe system types, determine the corresponding colors, adjust the graphical overrides accordingly, and automatically link identical material color codes with the same line color.

Since I couldn’t do this directly in the script, I tried overriding line colors via Excel.

Kind regards,

Kösedag Ünal


Original post below


Hallo zusammen,

ich möchte ein Dynamo-Skript erstellen, das die Materialfarbcodes der Rohrsystemtypen automatisch ausliest und diese Farben anschließend in die grafischen Überschreibungen der Linienfarben übernimmt. Dabei sollen Rohrsystemtypen mit demselben Materialfarbcode automatisch die gleiche Linienfarbe in den grafischen Überschreibungen erhalten.

Ziel ist es, die Farbdefinitionen konsistent zu halten und den manuellen Aufwand bei der Pflege der grafischen Darstellung zu reduzieren.

Konkret soll das Skript: die Materialfarbcodes der Rohrsystemtypen auslesen, die zugehörigen Farben ermitteln, die grafischen Überschreibungen entsprechend anpassen, und identische Materialfarbcodes automatisch mit derselben Linienfarbe verknüpfen.

Weil ich nihct direkt im Skript geschafft habe, habe versucht über Excel Linienfarben zu überschreiben.

Freundliche Grüsse

Kösedag Ünal

Welcome to the forum @Uenal.Koesedag9GSXG.

Unfortunately the official language here is English (annars skulle jag svara på svenska så att jag kunde öva). Sadly this is a requirement to make search work along with so many other technical things, so please translate all future posts prior to hitting send using the web service of your choice. You’re welcome to keep your native language post on there as well so long as you put a clear divisor between it and the English post as I did in the edit of your original post - doing so can help should we ever get multi-language support in the forum.

Why isn’t it working?

Grafik duct and pipe systems V2.dyn (40.5 KB)

hi @Uenal.Koesedag9GSXG maybe becaurse you try get material from system type, guess you are more after get material from elements on these systemtypes…maybe :wink:

@sovitek Thank you very much for your answer. Exactly, I want to get material of a certain system type and override line colors in the same system type. But I can’t figure it out.

try genius loci there is some nodes for set /get the pure systemtype graphic properties and could probably help if your pipes/ ducts isnt overridden by filter or other things…hope is what you are after…but not 100 :wink:

I’ve already tried this solution, and you’re right it doesn’t quite work, unfortunately. Is it possible to solve the problem using a Python script?

what doesnt work is it get systemtype or get or set graphic…for get the graphic try as here for cpyhon3 or pythonnet 3 and …show us exackly what all you nodes give and can probably help…

import clr
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference('DSCoreNodes')
import DSCore
from DSCore import Color

elements = UnwrapElement(IN[0]) if isinstance(IN[0], list) else [UnwrapElement(IN[0])]

systype,name,classification,abbreviation,lineWeight,lineColor,linePattern,material,types,category=[],[],[],[],[],[],[],[],[],[]

for elem in elements:
    if isinstance(elem, Autodesk.Revit.DB.ElementType):
        systype.append(elem)
    else:
        system = None
        if elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM):
            system = elem.get_Parameter(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM).AsElementId()
        elif elem.get_Parameter(BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM):
            system = elem.get_Parameter(BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM).AsElementId()
        systype.append(doc.GetElement(system) if system is not None else None)
    category.append(Revit.Elements.Category.ById(elem.Category.Id.Value))

for i in systype:
    if i is not None:
        name.append(i.ToDSType(True).Name)
        classification.append(i.SystemClassification)
        abbreviation.append(i.Abbreviation)
        linePattern.append(doc.GetElement(i.LinePatternId))
        try:
            lineColor.append(DSCore.Color.ByARGB(255, i.LineColor.Red, i.LineColor.Green, i.LineColor.Blue))
        except Exception:
            lineColor.append(None)
        lineWeight.append(i.LineWeight)
        material.append(doc.GetElement(i.MaterialId))
    else:
        name.append(None)
        classification.append(None)
        abbreviation.append(None)
        linePattern.append(None)
        lineColor.append(None)
        lineWeight.append(None)
        material.append(None)

if isinstance(IN[0], list):
    OUT = systype,name,classification,abbreviation,linePattern,lineColor,lineWeight,material,category
else:
    OUT = systype[0],name[0],classification[0],abbreviation[0],linePattern[0],lineColor[0],lineWeight[0],material[0],category[0]

and for set graphic genius loci should work for ironpython 2.7 version 2.5 package and direckly with pythonnet 3 , and then you need the pythonnet 3 package 1.0 installed…depends version

and PS if is pipe system types there struggle then just use ootb instead

@sovitek Thank you so much for your support. I’ve already adjusted the script, but it’s not happening :frowning:

Grafik duct and pipe systems V3.dyn (26.3 KB)

allright can you share a small rvt sample..where it doesnt work, and we can take a look…btw which revit version are you in ?

i have just open you graph you still use some custom node for get pipesystemtype use ootb

@sovitek Thank you so much for your support. Here are my files. I’m using Revit 2025 and Dynamo 3.3. I’m also attaching a Revit file and Dynamo script via WeTransfer because the file was too large to upload.

https://we.tl/t-nvx6vbgzxTUij8pf

alright the link doesnt work

but it works from my side here with cpython 3 or pythonnet 3…if it doesnt work for you and in your graph, its probably how you sort and do…but i havent goin into that
test graphic.dyn (33.8 KB)

@sovitek Hi again, thanks so much for your support. I ran your test script, but the line colors of the pipes, which were supposed to inherit the material colors, didn’t work. I’m sending a link to the Revit file.

i dont wanna by in dyn today, but genius loci should have nodes as well for get material color

You have a lot of system types with no material assigned—that results in null values. Try cleaning that up… give something like this a try and see if it works better.

@sovitek Hi again, thanks so much for your support. I’ve adjusted the script, but the line colors are still the same :frowning:

set lacing to longest maybe

Revit_9bd5MJkNfo