[摘要] Revit开发设置模型线颜色!Revit里要设置模型线的颜色有2中方法一种是设置线的样式一种是设置OverrideGraphicSettings第一种需要设置新
Revit开发设置模型线颜色!Revit里要设置模型线的颜色有2中方法
一种是设置线的样式
一种是设置OverrideGraphicSettings
第一种需要设置新建线的样式,
然后通过模型线的线样式参数设置
第二种是通过替换视图中的图形,它是
基于视图的,颜色只在当前视图有效
下面是关键代码:
新建线样式
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("线样式");
tp.Set(mgs.Id);
trans.Commit();
替换视图中的图形
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();
【相关技巧搜索】
关于Revit模型线颜色