Setting Model Line Colors in Revit Development
There are two main methods to set the color of model lines in Revit:
1. Setting the line style
2. Using OverrideGraphicSettings
The first method involves creating and defining a new line style, then applying this style to the model line. The second method is view-specific, where the graphics are overridden only within the current view.
Below is the essential code for each method:
Creating a New Line Style
Category tCat = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
Reference r = uidoc.Selection.PickObject(ObjectType.Element);
Element elem = doc.GetElement(r);
Transaction trans = new Transaction(doc, "Trans");
trans.Start();
if (!tCat.SubCategories.Contains("MyLine"))
{
Category nCat = doc.Settings.Categories.NewSubcategory(tCat, "MyLine");
nCat.LineColor = new Color(255, 0, 0);
}
doc.Regenerate();
FilteredElementCollector temc = new FilteredElementCollector(doc);
temc.OfClass(typeof(GraphicsStyle));
GraphicsStyle mgs = temc.First(m => (m as GraphicsStyle).GraphicsStyleCategory.Name == "MyLine") as GraphicsStyle;
Parameter tp = elem.LookupParameter("Line Style");
tp.Set(mgs.Id);
trans.Commit();
Overriding Graphics in the View
Reference r = uidoc.Selection.PickObject(ObjectType.Element);
Element elem = doc.GetElement(r);
OverrideGraphicSettings ogs = v.GetElementOverrides(elem.Id);
Transaction trans = new Transaction(doc, "trans");
trans.Start();
ogs.SetProjectionLineColor(new Color(255, 0, 0));
v.SetElementOverrides(elem.Id, ogs);
trans.Commit();
Related Skills Search
About Revit Model Line Colors











Must log in before commenting!
Sign Up