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: 

How to Pick a View using ISelectionFilter

4 REPLIES 4
Reply
Message 1 of 5
Todd_Jacobs
849 Views, 4 Replies

How to Pick a View using ISelectionFilter

Need help creating filter for View

Thanks

Jim

 

//Comments removed for brevity 

namespace TESTING.View.Select
{
    public class MySelectView : IExternalCommand
    {

       UIDocument m_document;
       public Autodesk.Revit.UI.Result Execute(Autodesk.Revit.UI.ExternalCommandData commandData,
            ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                m_document = commandData.Application.ActiveUIDocument;

                Reference viewRef = m_document.Selection.PickObject(ObjectType.Element, new ViewFilter(m_document.Document), "Please pick a View. ESC for cancel.");

                return Result.Succeeded;
            }
            catch (Exceptions.OperationCanceledException)
            {
                // Selection Cancelled. For picking face and picking point.
                return Result.Cancelled;
            }
            catch (System.Exception ex)
            {
                // If any error, give error information and return failed
                message = ex.Message;
                return Result.Failed;
            }
        }
    }

    public class ViewFilter : ISelectionFilter
    {

        Document m_doc = null;

        public ViewFilter(Document doc)
        {
            m_doc = doc;
        }

        public bool AllowElement(Element element)
        {
            return element is Autodesk.Revit.DB.View;
        }

        public bool AllowReference(Reference refer, XYZ point)
        {
            return false;
        }
    }
}

 

4 REPLIES 4
Message 2 of 5
phildebrandt
in reply to: Todd_Jacobs

What kind of help? Does your code generate an error?

Message 3 of 5
Todd_Jacobs
in reply to: phildebrandt

 

No runtime error is generated, but when the cursor hovers over a view object it is not allowing it to be selected, the cursor remains as a circle with a slash, I need help with the selection filter code to accept a View object

 

Thanks,

Jim

Message 4 of 5
Todd_Jacobs
in reply to: Todd_Jacobs

[Edit]

I am not sure if I should be filtering for a View , I did not see a ViewPort class, it's the ViewPort on the sheet which is to be selected

 

Thanks,

Jim

Message 5 of 5
Todd_Jacobs
in reply to: Todd_Jacobs

I modified the ViewFilter class to this and it seems to work, but is it the correct way of doing it?

 

Thanks,

Jim

 

    public class ViewFilter : ISelectionFilter
    {
        // Revit document.
        Document m_doc = null;

        /// <summary>
        /// Constructor the filter and initialize the document.
        /// </summary>
        /// <param name="doc">The document.</param>
        public ViewFilter(Document doc)
        {
            m_doc = doc;
        }

        /// <summary>
        /// Allow View - ViewPort? to be selected
        /// </summary>
        /// <param name="element">A candidate element in selection operation.</param>
        /// <returns>Return true for View - ViewPort?. Return false for non View - ViewPort? element.</returns>
        public bool AllowElement(Element element)
        {

            Reference myView = new Reference(element);

            if (null != myView)
            {
                if ("324" == m_doc.GetElement(myView).GetTypeId().ToString())
                    return true;
                else
                    return false;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// No reference to be selected
        /// </summary>
        /// <param name="refer">A candidate reference in selection operation.</param>
        /// <param name="point">The 3D position of the mouse on the candidate reference.</param>
        /// <returns>Return true for reference. Return false non reference.</returns>
        public bool AllowReference(Reference refer, XYZ point)
        {
            return true;
        }
    }

 

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

Post to forums  

Rail Community


Autodesk Design & Make Report