BIM World
A Professional BIM Learning Platform


How to Set Model Line Colors in Revit Development

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

xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat
Like(0) 打赏
BIM WORLD » How to Set Model Line Colors in Revit Development

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up