From 052b4e841eb56426bb40da87052eb2aa7f4d5d16 Mon Sep 17 00:00:00 2001 From: Deniz <55183821+denizmaral@users.noreply.github.com> Date: Thu, 18 Jan 2024 13:02:24 +0100 Subject: [PATCH] Update Category.cs That would be nice to create an instance by ElementId since ElementId.IntegerValue would be obsolete soon. --- src/Libraries/RevitNodes/Elements/Category.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Libraries/RevitNodes/Elements/Category.cs b/src/Libraries/RevitNodes/Elements/Category.cs index 2ace1691d7..6158986faf 100644 --- a/src/Libraries/RevitNodes/Elements/Category.cs +++ b/src/Libraries/RevitNodes/Elements/Category.cs @@ -113,7 +113,28 @@ public static Category ById(long id) throw new ArgumentException(Properties.Resources.InvalidCategory); } } + /// + /// Gets Revit Built-in category from current document based on category Id + /// + /// Category Id as ElementId + /// Category if present in current document. + [IsVisibleInDynamoLibrary(false)] + public static Category ById(ElementId categoryId) + { + try + { + var document = DocumentManager.Instance.CurrentDBDocument; + Autodesk.Revit.DB.Category category = Autodesk.Revit.DB.Category.GetCategory(document, categoryId); + if(null == category) + throw new ArgumentException(Properties.Resources.InvalidCategory); + return new Category(category); + } + catch + { + throw new ArgumentException(Properties.Resources.InvalidCategory); + } + } #endregion public override string ToString()