Change color of a linestyle

This should do the trick:

# Copyright(c) 2017, Konrad K Sobon
# @arch_laboratory, http://archi-lab.net

import clr

# Import Element wrapper extension methods
clr.AddReference("RevitNodes")
import Revit

clr.ImportExtensions(Revit.Elements)

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

# Import RevitAPI
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *

import sys

pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)

try:
	errorReport = None
	
	TransactionManager.Instance.EnsureInTransaction(doc)
	
	cat = Category.GetCategory(doc, BuiltInCategory.OST_Lines)
	gs = cat.GetGraphicsStyle(GraphicsStyleType.Projection)
	gsCat = gs.GraphicsStyleCategory.SubCategories
	
	style = next((i for i in gsCat if i.Name == IN[0]), None)
	if style != None:
		style.LineColor = Color(IN[1].Red, IN[1].Green, IN[1].Blue)
	
	TransactionManager.Instance.TransactionTaskDone()
	
except:
	# if error accurs anywhere in the process catch it
	import traceback
	errorReport = traceback.format_exc()

#Assign your output to the OUT variable
if errorReport == None:
	OUT = style.GetGraphicsStyle(GraphicsStyleType.Projection)
else:
	OUT = errorReport

Couple of sidenotes:

@Yna_Db please refrain from answering the question with multiple links that don’t really provide an answer, nor bring the OP closer to an answer.
@Tom_Kunsman Your link was a good place to start. Following the code in that post the OP would have been able to get the line styles and their properties so that’s for sure a step in the right direction. Thanks for sharing.
@3Pinter Your assessment that the LineColor was a read only property was wrong because you were looking at the wrong property. It’s not the GraphicsStyleCategory that holds the LineColor but the Category itself.

image

Cheers!

6 Likes