Projection Line Color in Python

I am trying to overwrite the projection line colors of structural framing elements with Python.

So far I came up with this;

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager 

doc = DocumentManager.Instance.CurrentDBDocument


view = IN[0]
elements = IN[1]
#color_from_node = IN[2]
element_id = [3]

color = Autodesk.Revit.DB.Color(255,255,255)

output = []


ogs = OverrideGraphicSettings().SetProjectionLineColor(color)

#for i in elements:
	#doc.ActiveView.SetElementOverrides((i.Id), ogs)



OUT = view, elements, color, ogs

However when I set the SetElemenOverrides in the for loop it asks for an ElementId instead of Element. So I type i.Id. However then Python says I am trying to pass an integer instead of an ElementId. Am I missing some step to tell Python it’s an ElementId instead of an integer?

You can convert the integer to an ElementId with doc.ActiveView.SetElementOverrides(ElementId(i.Id), ogs). You’ll need to start and end transaction as well.

1 Like

Nice, worked like a charm! :grin:

For those who are interested, the code and result

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

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

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager 

from System.Collections.Generic import List



doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

view = IN[0]
elements = IN[1]


color = Autodesk.Revit.DB.Color(255,25,0)

output = []


ogs = OverrideGraphicSettings().SetProjectionLineColor(color)

	
for i in elements:
	doc.ActiveView.SetElementOverrides(ElementId(i.Id), ogs)


TransactionManager.Instance.TransactionTaskDone()

The result;

On a side note, I spent almost half the day googling and trying to understand the Python API. I can’t seem to find any documentation for this.

http://www.revitapidocs.com/

1 Like