pickobject

pickobject

Anonymous
Not applicable
2,150 Views
3 Replies
Message 1 of 4

pickobject

Anonymous
Not applicable

Hi,

 

I can use prompt the user to select an element from the linked revit model:

Reference refElemLinked;
                try
                {
                     refElemLinked = uidoc.Selection.PickObject(ObjectType.LinkedElement, "Please pick an element in the linked model");
                }
                catch (Exception exq)
                {
                   
                    
                }

I can use prompt the user to select an element from the revit model:

Reference refElemLinked;
                try
                {
                     refElemLinked = uidoc.Selection.PickObject(ObjectType.Element, "Please pick an element in the linked model");
                }
                catch (Exception exq)
                {
                    
                    
                }

But how do I prompt the user to select an element irrespective of the main model or the linked model.

 

 

Thanks & Regards

Sanjay Pandey

0 Likes
2,151 Views
3 Replies
Replies (3)
Message 2 of 4

htlcnn
Enthusiast
Enthusiast

You should use PickElementsByRectangle: http://www.revitapidocs.com/2018/ff8f9e7f-cc92-fe92-6ea4-9f1b581f2bac.htm

Because PickObject only allows 1 ObjectType, and Enum can not be inherited from two other Enums

0 Likes
Message 3 of 4

RPTHOMAS108
Mentor
Mentor

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
0 Likes
Message 4 of 4

Anonymous
Not applicable

Hi,

 

Thanks for the response.

 

I implemented a simple and easy approach. Before processing I ask from the user that he wants to select from linked model or the main model.

if he chooses main model

Reference refElemLinked;
                try
                {
                     refElemLinked = uidoc.Selection.PickObject(ObjectType.Element, "Please pick an element in the linked model");
                }
                catch (Exception exq)
                {
                    
                    
                }

 

if he chooses linked model

Reference refElemLinked;
                try
                {
                     refElemLinked = uidoc.Selection.PickObject(ObjectType.LinkedElement, "Please pick an element in the linked model");
                }
                catch (Exception exq)
                {
                   
                    
                }

Thanks & Regards

Sanjay Pandey

0 Likes