Thursday, March 25, 2010

Revit API 2011: Ooh Ooh! Pick Me!

(Part of our Revit API 2011 Series)
The Revit 2011 API adds some new ways to interact with elements in the project – through picking. These are all available through the UIDocument.Selection class:

  • PickObject (replaces PickOne – pick something in the active view – get back a reference)
  • PickObjects – pick multiple objects, click “Finish” when done.
  • PickElementsByRectangle – a replacement for “WindowSelect”
  • PickPoint – return an XYZ coordinate based on picking on the active workplane

What’s Even Better?

All of the above except for PickPoint support a number of options that go deeper than what we had in Revit 2010 and prior (where you could only support picking full elements):

  • Element (as before a whole element)
  • Face (a specific face of an element)
  • Edge (any model edge)
  • PointOnElement (any point on any face or curve)

Further, the methods mentioned above also support a new concept as well – a Selection Filter interface: ISelectionFilter. You can implement ISelectionFilter on any class – it will get callbacks from the pick method to help you control what is allowed to be selected or not:

  • a Pre-filter method at the element-level
  • a Post-filter method at the reference-level

This lets you easily limit your selections to, for example, “walls” or “exterior walls” or “an inside horizontal top edge of an exterior wall” – the mind boggles.

But Wait, There’s More!

While PickPoint() does not support the options described above – it DOES support a different set of options – Object Snaps!

  • Points - Snaps to site points.
  • Quadrants - Snaps to quadrant points. For arcs, jump snaps are enabled.
  • Tangents - Snaps tangent to an arc.
  • Perpendicular - Snaps to perpendicular elements or components.
  • Centers - Snaps to the center of an arc.
  • Intersections - Snaps to intersections.
  • WorkPlaneGrid - Snaps to a work plane grid.
  • Nearest - Snaps to the nearest element or component.
  • Midpoints - Snaps to the midpoint of an element or component.
  • Endpoints - Snaps to the endpoint of an element or component.

Conclusion

The Pick mechanism in Revit has gone from paltry to an embarrassment of riches… I’m not aware of a better Pick API in any CAD system. While there are still a few usability oddities, it’s a vast improvement over 2010.

4 comments:

Ceorl said...

Hi Matt,
Do you know of a way to create the rubber band effect while picking two points in Revit? Something akin to what you see while drawing Model Lines. I don't believe the API supports it, but is there a possible workaround?

Matt Mason said...

Ceorl,

No - that's an obvious limitation.
There's not even a callback that you could tie to during the pick process.

Short of doing something really weird - like overlaying your own transparent window over the model window (which i think you have more tools to do so in 2011) - I don't think there's a way with the API.

-Matt

Ceorl said...

OK, I understand that, so riddle me this: I see the ability to insert families using the PromptForFamilyInstancePlacement method. Is it possible to insert a group?

Thanks,
Ceorl

Matt Mason said...

Hmm - sadly no, if I recall correctly the input to the PromptForFamilyInstancePlacement method is a FamilySymbol - so a group is not possible.

you can place a (pre-loaded) group, given the X,Y coordinates (perhaps from PickPoint). Or if you're looking for something with more of a jig, you could place a "placeholder family" - then swap in a group at the placed location.


None of which are ideal, I'm well aware :)