Allowing multiple ObjectTypes within a PickObject

Allowing multiple ObjectTypes within a PickObject

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

Allowing multiple ObjectTypes within a PickObject

Anonymous
Not applicable

Hello,

I am trying to programmatically decide which line of code to run based what the user is hovering the mouse over.

for example:

 

if the mouse cursor is hovering over a Wall, Mechanical Equipment, Column, etc.:

 

r = uidoc.Selection.PickObject(ObjectType.Face, "Select a face");

if the mouse cursor is hovering over a Duct, Pipe, etc.

 

 

r = uidoc.Selection.PickObject(ObjectType.Edge, "Select a edge");

 

Ideally, I would use Edge in all cases. Because getting the edge of an element is my end goal. Unfortunately, there are certain situations where a Wall or Column edge is not available for selection (I assume because of the view range) in a Plan View. (the edge can be selected in a 3D view - this is why I assume its a view range issue?). 

 

The problem with just keeping it at ObjectType.Face for all cases, is that this doesn't work too well with round ducts, pipes, oval ducts, conduits etc.

What the user is trying to do is select an outside edge of something.

 

I tried configuring an IselectionFilter to dynamically allow me to select an edge if the element was a duct. And a face for anything else. But the user is still locked out of selecting anything other than the ObjectType.

 

I was hoping this would have worked:

 

r = uidoc.Selection.PickObject(ObjectType.Edge | ObjectType.Face, "Select an edge or a face");

But unfortunately it did not. 

 

 

I tried following Jeremy's blog post on his toolTip add-in. I was hoping to re-use some of the code that reported what element was under the mouse cursor. But after a while I couldn't get it to work correctly. 

http://thebuildingcoder.typepad.com/blog/2012/10/uiview-windows-coordinates-referenceintersector-and...

 

I also tried something like this:

public Curve GetElementCurve()
{
if (RefInt = null)
r = uidoc.Selection.PickObject(ObjectType.Element, selFilter, "Select an element");
if (RefInt = 1)
r = uidoc.Selection.PickObject(ObjectType.Edge, selFilter, "Select an edge");
if (RefInt = 2)
r = uidoc.Selection.PickObject(ObjectType.Face, selFilter, "Select an face");
}

public bool AllowElement(Element elem)
{
View activeView = ui_doc.ActiveView;
ElementId elemTypeId = elem.GetTypeId();
ElementType elemType = m_doc.GetElement(elemTypeId) as ElementType;
string category = elemType.Category.Name;
string[] edgeCategories = { "Ducts", "Pipes" };
foreach (string s in edgeCategories)
{
if (category.Contains(s))
{
Command.RefInt = 1;
Command.GetElementCurve(ui_doc, m_doc, activeView, ui_app);
}
if (!category.Contains(s))
{
Command.RefInt = 2;
Command.GetElementCurve(ui_doc, m_doc, activeView, ui_app);
}
}
return true;
}

I found that this almost works. RefInt is correctly set, and I go back into the GetElementCurve method with the new RefInt value. But it appeared that the add-in was still not going to allow me to select that Edge or Face depending on the situation. I was still being prompted for the Element.

 

Is there an easier solution to all of this? Is there some setting to allow the user to select a wall edge regardless of the view range?

 

I know I can probably first prompt the user to select an Element. And from there programmatically decide if a face or edge needs to be selected. But I am trying to avoid having that extra click. 

 

I have a feeling there is something simple that I missing here, and I'm making this more complicated than it need be. 

Thanks for taking the time getting through this confusing post!

0 Likes
Accepted solutions (1)
2,760 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

Dear Pat,

 

i face issue like same for Pipe, Duct & CableTray,

In my situation i have to restrict user to select a point on centerline of Pipe,Duct,CableTray. 

To overcome issue  i use below code that help me lot. I am not sure this will also help you. But you can try once.

 

Edge and Face selection depends on view.

 

 

 

   ElementSelectionFilter ef = new ElementSelectionFilter();
   Selection sel = _uidoc.Selection;
   Reference reference = sel.PickObject(ObjectType.PointOnElement, ef, "Please Select Pipe/Duct/CableTray");




 public class ElementSelectionFilter : ISelectionFilter
    {
      
{
        public bool AllowElement(Autodesk.Revit.DB.Element e)
        {
           // return (e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_Lines));
            if (e is Pipe )
            {
 
if(RevitFunctions.GetCenterline(e as Pipe)!=null)
{
                return true;
}
            }
            else if(e is Duct )
            {
               if( RevitFunctions.GetCenterline(e as Duct)!=null)
{
                return true;
}
            }
            else if (e is CableTray)
            {
              if( RevitFunctions.GetCenterline(e as CableTray))
{
                return true;
}
            }
            else
            {
                return false;
            }

        }
}


       public static Line GetCenterline(Pipe _pipe)
        {
            Options options = new Options();
            options.ComputeReferences = true; //!!!
            options.IncludeNonVisibleObjects = true; //!!! 
            if (_pipe.Document.ActiveView != null)
                options.View = _pipe.Document.ActiveView;
            else
                options.DetailLevel = ViewDetailLevel.Fine;

            var geoElem = _pipe.get_Geometry(options);
            foreach (var item in geoElem)
            {
                Line lineObj = item as Line;
                if (lineObj != null)
                {
                    return lineObj;
                }
            }
            return null;
        }
0 Likes
Message 3 of 4

Anonymous
Not applicable

try using ObjectType.PointOnElement which will let you select faces or edges

 

Message 4 of 4

Anonymous
Not applicable

Thank you both for your solutions. I was starting to think that PointOnElement was going to be the only solution. 

Fortunately I was able to add enough code in the AllowReference section to explicity deny or allow certain types of references from there.

0 Likes