IMPLEMENTING ISELECTION INTERFACE FOR SECLECTING SOME SPECIFIC ELEMENTS IN VIEW

IMPLEMENTING ISELECTION INTERFACE FOR SECLECTING SOME SPECIFIC ELEMENTS IN VIEW

AGYEMANG.OFOSU
Advocate Advocate
515 Views
1 Reply
Message 1 of 2

IMPLEMENTING ISELECTION INTERFACE FOR SECLECTING SOME SPECIFIC ELEMENTS IN VIEW

AGYEMANG.OFOSU
Advocate
Advocate

I am trying to select three different categories of elements using the iselectionfilter but my conditional clause to select beams in they normal to view is not working



public class Support : ISelectionFilter private bool IsEligibleSupport(Element element) { BeamGeometry beamgeometry = new BeamGeometry(Doc); bool beamparallel=beamgeometry.IsParallelToView(Doc,element); int CategoryId= element.Category.Id.IntegerValue; if (CategoryId==(int)BuiltInCategory.OST_StructuralColumns||
CategoryId==(int)BuiltInCategory.OST_Walls) if(CategoryId==(int)BuiltInCategory.OST_StructuralFraming &&
beamparallel == true) return false; return true; } public bool AllowElement(Element ele) { if(IsEligibleSupport(ele) ) return true; return false; } public bool AllowReference(Reference r, XYZ point) { return true; } }
0 Likes
Accepted solutions (1)
516 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk
Accepted solution

Here is a nice clean readable code snippet to check whether the category equals one of the target ones:

  

    public bool AllowElement( Element e )
    {
      bool rc = null != e.Category;
      if( rc )
      {
        int[] targets = new int[] {
          (int) BuiltInCategory.OST_StructuralColumns,
          (int) BuiltInCategory.OST_StructuralFraming,
          (int) BuiltInCategory.OST_Walls
        };

        int icat = e.Category.Id.IntegerValue;

        rc = targets.Any<int>( i => i.Equals(icat) );
      }
      return rc;
    }

  

It uses the System.Linq namespace.

 

You could avoid that by implementing your own comparison in a simple loop.

  

Cheers,

 

Jeremy

 



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