How to Pick a Edge using ISelectionFilter in a linked model

How to Pick a Edge using ISelectionFilter in a linked model

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

How to Pick a Edge using ISelectionFilter in a linked model

Anonymous
Not applicable

Hi,

I need to enable user to select edge from a Revit linked model, how can I do to implement  ISelectionFilter interface to select edge in revit linked model?

Cheers

Max

 

faceRef = uidoc.Selection.PickObject(ObjectType.LinkedElement,
                            new EdgeFilter(uidoc.Document),"Please pick a edge on a linked model to get it. ESC for terminate.");

 

 public class EdgeFilter : ISelectionFilter
    {
        Document m_doc = null;
        public EdgeFilter(Document doc)
        {
            m_doc = doc;
        }
        public bool AllowElement(Element element)
        {         
            return false;
        }      
        public bool AllowReference(Reference refer, XYZ point)
        {
            //Debugger.Break();
            GeometryObject geoObject =
            m_doc.GetElement(refer)
                 .GetGeometryObjectFromReference(refer);
            return geoObject != null && geoObject is Edge;
        }

    }

2,231 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

Dear Max,

 

Thank you for your query.

 

Interesting.

 

Yes, strangely enough, the ObjectType enumeration include:

 

  • Nothing Nothing. 
  • Element Whole element. 
  • PointOnElement Any point on an element (on a face or curve). 
  • Edge Any model edge. 
  • Face Any face. 
  • LinkedElement Elements in linked RVT files.

 

From the list above, it seems like EdgeInLinkedFile would be necessary in your case.

 

However, I know that requesting ObjectType.Edge or Face also returns the selected element, and requesting Element also returns the picked point.

 

What happens when you use the code you provided?

 

What happens when you try the other options in a linked file, e.g. Edge?

 

By the way, you can use the {i} Insert Code icon above to insert more legible source code.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

Anonymous
Not applicable

Hi Jeremy, I have changed my code, it works fine if for example I want to select and filter justa wall in my linked model, but it doen't works if I want to select and filter just Edge, fc is always null!!

Any workaround?

Cheers

Max

 

 

 

faceRef = uidoc.Selection.PickObject(ObjectType.LinkedElement,new EdgeFilter(), "Please pick a edge on a linked model to get it. ESC for terminate.");

public class EdgeFilter : ISelectionFilter

{

private RevitLinkInstance m_currentInstance = null;

//public EdgeFilter(Document doc)

//{

// m_doc = doc;

//}

public bool AllowElement(Element e)

{

// Accept any link instance, and save the handle for use in AllowReference()

m_currentInstance = e as RevitLinkInstance;

return (m_currentInstance != null);

}

public bool AllowReference(Reference refer, XYZ point)

{

if (m_currentInstance == null)

return false;

// Get the handle to the element in the link

Document linkedDoc = m_currentInstance.GetLinkDocument();

Element elem = linkedDoc.GetElement(refer.LinkedElementId);

GeometryObject geoObject =

elem.GetGeometryObjectFromReference(refer);

Edge fc = geoObject as Edge;

return elem != null && fc !=null;

 

/*

Element elem = linkedDoc.GetElement(refer.LinkedElementId);

// Accept the selection if the element exists and is of the correct type

return elem != null && elem is Wall;

*/

}

 

0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk

Dear Max,

 

Thank you for your update and clarification.

 

Cool.

 

You new selection filter gave me an idea.

 

What document were you passing in to the original selection filter to populate m_doc?

 

Are you sure that was the linked document that the element lives in?

 

And that the element is an element from the linked document, not some kind of intermediate copy?

 

The same question applies to the new implementation also.

 

There are lots of tricky things to keep in mind when dealing with and trying to identify references.

 

I recently analysed some of them in my discussion on DirectShape From Face, where I use the ConvertToStableRepresentation method to identify a picked face:

 

http://thebuildingcoder.typepad.com/blog/2015/09/directshape-from-face-and-sketch-plane-reuse.html

 

This ConvertToStableRepresentation method may in fact give you a lot of what you need.

 

Look at these other examples of using it:

 

 

Looking forward to hearing what else you find out.

 

Good luck!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes