При работе с приложением TeхноНИКОЛЬ КЛИН (посмотреть видео тут) я столкнулся с тем, что метод NewTag, возвращающий новую марку, для экземпляра класса Autodesk.Revit.Creation.Document, устарел.
Метод "NewTag" все еще может использоваться для приложений для Revit версий 2017 и 2018 , но в Revit API 2019 этот метод уже удален. В 2018 и 2019 Revit API используется новый статический метод "Create" для класса IndependentTag, который возвращает экземпляр IndependentTag.
Тенденция следующая - все больше классов в Revit API получают собственный статический метод Create для создания собственных экземпляров, а не поручают это экземпляру класса Autodesk.Revit.Creation.Document. Возможно этот класс в будущем будет выведен из Revit API.
Для создания марки в своем приложении для Revit, для версий 2017 - 2019 можно воспользоваться возможностями библиотеки System.Reflection.
Сначала пробуем получить объект MethodInfo для версии 2019 Revit:
typeof(IndependentTag).GetMethod("Create", new Type[] { typeof(Document), typeof(ElementId), typeof(Reference), typeof(bool), typeof(TagMode), typeof(TagOrientation), typeof(XYZ) })
Если такого метода не существует, значит приложение запущено в Revit 2017. Для него получаем метод:
typeof(Autodesk.Revit.Creation.Document) .GetMethod("NewTag", new Type[] { typeof(Autodesk.Revit.DB.View), typeof(Element), typeof(bool), typeof(TagMode), typeof(TagOrientation), typeof(XYZ) })
Обратите внимание, в дальнейшем, вызов первого метода (API 2018-2019) будет статический, для вызова второго метода (API 2017) передаем объект класса Autodesk.Revit.Creation.Document - doc.Create.
Полный код метода GetIndependingTag, который возвращает экземпляр класса IndependentTag, независимо от версии Revit API, представлен ниже.
Показать код C# →
private IndependentTag GetIndependingTag(Document doc, Element el, XYZ point)
{
MethodInfo method = typeof(IndependentTag).GetMethod("Create", new Type[] { typeof(Document),
typeof(ElementId), typeof(Reference), typeof(bool), typeof(TagMode), typeof(TagOrientation), typeof(XYZ) });
if (method != null)
{
Reference elRef = new Reference(el);
return method.Invoke(null, new object[] { doc, doc.ActiveView.Id,
elRef, false, TagMode.TM_ADDBY_MULTICATEGORY, TagOrientation.Horizontal, point })
as IndependentTag;
}
else
{
MethodInfo method2 = typeof(Autodesk.Revit.Creation.Document)
.GetMethod("NewTag", new Type[] { typeof(Autodesk.Revit.DB.View),
typeof(Element), typeof(bool), typeof(TagMode), typeof(TagOrientation), typeof(XYZ) });
if (method2 != null)
{
return method2.Invoke(doc.Create, new object[] { doc.ActiveView, el,
false, TagMode.TM_ADDBY_MULTICATEGORY, TagOrientation.Horizontal, point }) as IndependentTag;
}
return null;
}
}