Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
urdiafa
1144 Views, 4 Replies

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

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:

4 REPLIES 4
Message 2 of 5
FAIR59
in reply to: urdiafa

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

Message 3 of 5
urdiafa
in reply to: FAIR59

Thank FAIR59,I still got error

 

s.2017-03-27-a.jpg

Message 4 of 5
FAIR59
in reply to: urdiafa

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
urdiafa
in reply to: FAIR59

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community