/// <summary> /// Set graphic attributes to <see cref="GeometryBase"/> <paramref name="geometry"/> from Context /// </summary> /// <param name="geometry"></param> /// <returns><paramref name="geometry"/> with graphic attributes</returns> static GeometryBase SetGraphicAttributes(GeometryBase geometry) { if (geometry is object) { var context = Context.Peek; if (context.Element is object) { if (context.GraphicsStyleId.IsValid() && context.Element.Document.GetElement(context.GraphicsStyleId) is DB.GraphicsStyle graphicsStyle) { var category = graphicsStyle.GraphicsStyleCategory; geometry.TrySetUserString(DB.BuiltInParameter.FAMILY_ELEM_SUBCATEGORY.ToString(), category.Id); } if (context.MaterialId.IsValid() && context.Element.Document.GetElement(context.MaterialId) is DB.Material material) { geometry.TrySetUserString(DB.BuiltInParameter.MATERIAL_ID_PARAM.ToString(), material.Id); } } } return(geometry); }
public static bool TrySetUserString(this GeometryBase geometry, string key, Autodesk.Revit.DB.ElementId value, Autodesk.Revit.DB.ElementId def) => geometry.TrySetUserString(key, value.IntegerValue, def.IntegerValue);