Revit API 2012 provides some more functionalities as always. It is good apparently. It also changes something, minor or major, also as always. Some changes are also good but some are not. One example is the Regeneration attribute and the RegenerationOption enumeration as discussed before.
Now another one exhibited itself when we were making the support for Revit API 2012 in Revit Addin Wizard (RevitAddinWizard) and this situation was much worse than that the RegenerationOption was involved in.
It is about the simple and good GeometryObject property of the Reference class. In Revit API 2011, we can retrieve the geometry object from a Reference directly by simply calling the GeometryObject property against the Reference itself. However, now the property has been marked as obsolete:
Reference Members
GeometryObject Obsolete.
The geometry item referred to by this reference.
When the Reference.GeometryObject was being called in some selection filters that were generated automatically by the Selection Filter Wizard, the following warning message showed up:
“Warning 1 'Autodesk.Revit.DB.Reference.GeometryObject' is obsolete: 'Property will be removed. Use Element.GetGeometryObjectFromReference(Reference) instead'”
To understand what the message was really trying to deliver, had a look at the Element.GetGeometryObjectFromReference(Reference) method for some details:
Element.GetGeometryObjectFromReference Method
Retrieve one geometric primitive contained in the element given a reference.
public GeometryObject GetGeometryObjectFromReference(
Reference reference
)
The big problem here is that the AllowReference method of the ISelectionFilter interface only carries a Reference and a XYZ argument in Revit API 2012 (the same as in the previous version) but as can be seen the GetGeometryObjectFromReference() method needs an Element instance to trigger it and no a static such method exists!
To make things clearer, a sample ISelectionFilter implementation generated automatically by RevitAddinWizard has been appended below:
public class Test_ISelectionFilter : Autodesk.Revit.UI.Selection.ISelectionFilter
{
public bool AllowElement(Element elem)
{
return false;
}
public bool AllowReference(Reference refer, XYZ pos)
{
if (refer.GeometryObject == null) return false;
if (refer.GeometryObject is Autodesk.Revit.DB.Curve) return true;
return false;
}
}
So how to ‘Use Element.GetGeometryObjectFromReference(Reference) instead' in this case then?
No idea! Maybe we have to use something like the following:
refer.Element.GetGeometryObjectFromReference(refer);
Please do not celebrate too early, however, because another similar warning message is right there waiting for us:
“'Autodesk.Revit.DB.Reference.Element' is obsolete: 'Property will be removed. Use Document.GetElement(Reference) instead'”
Even if the Referencce.Element will not be removed in the future, it still looks quite odd, at least to me (circulating long way around and finally returning to the start point! Somebody is lost in a desert, huh?). There may be some workaround for the problem but I believe it cannot be uglier.
Any suggestion then?
Simple like breathing air, keeping the Reference.GeometryObject property there.
The only good point is that the Reference.GeometryObject property is still there in Revit API 2012 for us to enjoy. Enjoy it for this moment then along with the powerful ISelectionFilter interface and the Selection Filter Wizard!
Therefore, Revit Addin Wizard (RevitAddinWizard) decided to keep using Reference.GeometryObject in its auto-generated selection filter code for Revit API 2012.
Recent Comments