using Autodesk.Revit.DB; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FWindSoft.Revit { public static class CurveElementExtension { public static GraphicsStyle GetGraphicStyle(this CurveElement curveElement,string styleName) { var ids = curveElement.GetLineStyleIds(); var document = curveElement.Document; foreach (var id in ids) { var style=document.GetElement(id) as GraphicsStyle; if(style!=null&&styleName== style.Name) { return style; } } return null; } public static GraphicsStyle SetLineStyle(this CurveElement curveElement, Color color, int lineWeight, string styleName) { if (string.IsNullOrWhiteSpace(styleName)) { styleName =string.Format(color.ToString()+"-"+ lineWeight); } var useStyle = curveElement.GetGraphicStyle(styleName); if (useStyle == null) { var subCategory = curveElement.Document.Settings.Categories.NewSubcategory(curveElement.Category, styleName); useStyle = subCategory.GetGraphicsStyle(GraphicsStyleType.Projection); } useStyle.GraphicsStyleCategory.LineColor = color; if (lineWeight > 0) { useStyle.GraphicsStyleCategory.SetLineWeight(lineWeight, GraphicsStyleType.Projection); } curveElement.LineStyle = useStyle; return useStyle; } } }