Autodesk . Revit DB Rectangle rect = UIView . GetWindowRectangle ();

Autodesk . Revit DB Rectangle rect = UIView . GetWindowRectangle ();

Anonymous
Not applicable
1,851 Views
4 Replies
Message 1 of 5

Autodesk . Revit DB Rectangle rect = UIView . GetWindowRectangle ();

Anonymous
Not applicable

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:

0 Likes
Accepted solutions (1)
1,852 Views
4 Replies
Replies (4)
Message 2 of 5

FAIR59
Advisor
Advisor

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();

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank FAIR59,I still got error

 

s.2017-03-27-a.jpg

0 Likes
Message 4 of 5

FAIR59
Advisor
Advisor
Accepted solution

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();

 

RevitAPIUI2016.JPG

 

Message 5 of 5

Anonymous
Not applicable

Thank FAIR59 , I really make this mistake , It can work , thank very much .

0 Likes