I try the code " Autodesk . Revit .DB .Rectangle rect = UIView . GetWindowRectangle (); " in Revit 2017 . I got the error " CS0120 An object reference is required for the non-static field , method ,or property 'UIView . GetWindowRectangle () ' " . How to cure it ? Any help will appreciate .
I know Rectangle class have moved from the UI namespace in the Revit 2015 and 2016 APIs to DB in Revit 2017:
Solved! Go to Solution.
Solved by FAIR59. Go to Solution.
you need a UIView object for the method to work.
IList<UIView> _uiViews = commandData.Application.ActiveUIDocument.GetOpenUIViews(); UIView _uiViewAct = null; foreach (UIView _uiview in _uiViews ) { if (_uiview.ViewId == document.ActiveView.Id) { _uiViewAct = _uiview; break; } } Autodesk.Revit.DB.Rectangle rect = _uiViewAct.GetWindowRectangle();
In the References section (Visual Studio) you most likely have loaded the 2016 RevitAPI.dll and RevitAPIUI.dll
if you want to compile for 2017 change the dll's for the 2017 version.
if you want to compile for 2016
change the code to
Autodesk.Revit.UI.Rectangle rect = _uiViewAct.GetWindowRectangle();