There is a two stage picking approach for single objects that could be adopted as below. It's not overly clunky, I work with what I have.
This is kind of an illusion because you can first pick any link and then pick an element from any other link.
It is probably possible to limit the second selection to an element in the original picked link using the ISelectionFilter. i.e. if you try to find the element based on UniqueID and it isn't found then element was not from that document, so return false.
If you were picking multiple elements then it would be PickObject followed by PickObjects.
Public Function Execute_TwoStepPicking(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData, _
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) _
As Autodesk.Revit.UI.Result
Dim IntApp As Autodesk.Revit.UI.UIApplication = commandData.Application
Dim IntUIDoc As Autodesk.Revit.UI.UIDocument = commandData.Application.ActiveUIDocument
If IntUIDoc Is Nothing Then Return Result.Cancelled Else
Dim IntDoc As Autodesk.Revit.DB.Document = IntUIDoc.Document
If IntDoc Is Nothing Then Return Result.Cancelled Else
Dim R As Reference = Nothing
Try
R = IntUIDoc.Selection.PickObject(Selection.ObjectType.Element, statusPrompt:="Select element or link")
Catch ex As Exception
End Try
If R Is Nothing Then Return Result.Cancelled Else
Dim El As Element = IntDoc.GetElement(R)
If El Is Nothing Then GoTo notsurewhatyoupicked Else
If El.GetType = GetType(RevitLinkInstance) Then
Dim Rlnk As Reference = Nothing
Try
Rlnk = IntUIDoc.Selection.PickObject(Selection.ObjectType.LinkedElement, statusPrompt:="Select element in link")
Catch ex As Exception
End Try
If Rlnk Is Nothing Then Return Result.Cancelled Else
Dim Li As RevitLinkInstance = IntDoc.GetElement(Rlnk)
Dim LinkedDoc As Document = Li.GetLinkDocument
Dim LinkedEl As Element = LinkedDoc.GetElement(Rlnk.LinkedElementId)
If LinkedEl Is Nothing Then GoTo notsurewhatyoupicked Else
MsgBox("You picked:" & LinkedEl.Name)
Else
MsgBox("You picked:" & El.Name)
End If
Return Result.Succeeded
notsurewhatyoupicked:
MsgBox("Don't know what you picked.")
Return Result.Succeeded
End Function