Check if a view has an active workplane set

Check if a view has an active workplane set

stever66
Advisor Advisor
1,872 Views
4 Replies
Message 1 of 5

Check if a view has an active workplane set

stever66
Advisor
Advisor

Having the user pick a 2D point in a view with selection.PickPoint("Please Pick a Point.") requires the view to have its active workplane set.   If the user hasn't ever selected an active workplane for the current view, PickPoint causes an exception.    Up until now, I've always just displayed an error dialog box that basically says "Set the views workplane to any valid plane, and try again. " 

 

I would like to make this a little more sophisticated by having my add-in set the workplane if necessary.   And I found this example:

https://forums.autodesk.com/t5/revit-api-forum/set-active-work-plane/td-p/3818199

 

But before I go setting the workplane, I'd like to check and make sure it hasn't already been set. (I don't want to change a workplane the user has set.)   I guess I could just check for an exception when asking for a PickPoint, but I assume there could be other reasons why an exception would occur (escape for example, or clicking outside the revit window maybe?)

 

I'm not seeing anything obvious in the API commands, and a google search has come up empty....So, is there any way to check and see if a view has its active workplane set?

 

  

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

Sean_Page
Collaborator
Collaborator

Maybe use the show /Hide active workplace method and Cath the exception of it doesn't have one first?

 

https://www.revitapidocs.com/2015/71eb322c-4781-2d86-1067-b6fe9648524f.htm

 

Or just handle the proper exception of the pick point and cycle the command again.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 3 of 5

jshial
Advocate
Advocate
Accepted solution

@stever66 @Sean_Page 

Try this, check if View.SketchPlane is null.

 

SketchPlane.PNG

Message 4 of 5

stever66
Advisor
Advisor

Thanks.

 

I thought of that too, but I believe I will also get an exception if the work plane happens to be outside the view range.

0 Likes
Message 5 of 5

Sean_Page
Collaborator
Collaborator

This is how I have handled the exception in the past. You can reference the API guide for which exceptions are thrown for what reason.

 

try
{
Point point = new UIDocument(doc).Selection.PickPoint("Select a Point");
}
catch (Exception ex)
            {
                if (ex.GetType() == typeof(Autodesk.Revit.Exceptions.InvalidOperationException))
                {
                    MessageBox.Show("Please Set a Work Plane for the Active view", "Work Plane", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (ex.GetType() == typeof(Autodesk.Revit.Exceptions.OperationCanceledException))
                {

                }
                else
                {
                    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes