Hello!
I’m very new to the Revit API. I am trying to get the color of line styles. It seems like something changed in R22 where the python script I used doesn’t work anymore. “i.LineColor” still works, but returns a System Object, not sure how to get the Red, Blue and Green values. I commented out the original line in the script below. Can anyone help? I would also greatly value some instruction on how to figure out how to find this information in the API.
Thanks!
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
lineStyle = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines)
lineStyleSubTypes = lineStyle.SubCategories
listNames = []
listRGB = []
lineWeight = []
listPattern = []
patname = []
listout = []
listpatid = []
for i in lineStyleSubTypes:
name = i.Name
#rgb = [i.LineColor.Red, i.LineColor.Green, i.LineColor.Blue]
rgb = i.LineColor
weight = i.GetLineWeight(GraphicsStyleType.Projection)
listNames.append(name)
listRGB.append(rgb)
lineWeight.append(weight)
id = i.GetLinePatternId(GraphicsStyleType.Projection)
pat = LinePatternElement.GetLinePattern(doc,id)
listPattern.append(pat)
listpatid.append(id)
try:
patname.append(pat.Name)
except:
patname.append("Solid")
style = i.GetGraphicsStyle(GraphicsStyleType.Projection)
listout.append(style)
# End Transaction
TransactionManager.Instance.TransactionTaskDone()
OUT = lineStyleSubTypes, listNames, listRGB, lineWeight, listPattern, patname, listpatid