首页 > 代码库 > Revit 二次开发 修改对象的颜色

Revit 二次开发 修改对象的颜色

//修改对象颜色

[TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class ChangeColor : IExternalCommand
{

    public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
    {
          ChangeElementColor(commandData, elements);
           return Result.Succeeded;
    }


    public void ChangeElementColor(ExternalCommandData   commandData, ElementSet elements)
    {
        UIApplication app = commandData.Application;
        Document doc = app.ActiveUIDocument.Document;

        ElementId el = new ElementId(729401);

        Transaction trans = new Transaction(doc);
        trans.Start("ChangeColor");
    
        Color color = new Color((byte)255, (byte)0, (byte)0);
        OverrideGraphicSettings ogs = new OverrideGraphicSettings();
        //设置ElementId为729401的Element的颜色
        ogs.SetProjectionLineColor(color);//投影表面线的颜色
        ogs.SetCutFillColor(color);//切割面填充颜色
        Autodesk.Revit.DB.View view = doc.ActiveView;
        view.SetElementOverrides(el, ogs);

        trans.Commit();
     } 
}