Get all associated Rebars which attach to the Structural Element

Get all associated Rebars which attach to the Structural Element

Anonymous
Not applicable
4,292 Views
5 Replies
Message 1 of 6

Get all associated Rebars which attach to the Structural Element

Anonymous
Not applicable

Hi

How can i get all associated Rebars which attach to the Structural Element such as a column by picking that?

 

0 Likes
Accepted solutions (1)
4,293 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

Use a filtered element collector.

 

Set it up to retrieve rebar elements only, and add a filter for the column solid:

 

 

Cheers,

 

Jeremy

 



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

Message 3 of 6

Anonymous
Not applicable

Thanks @jeremytammik
But the example of the link is for VB,

I used this code, but couldn't get answer, 

Reference pickedObj = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
            ElementId eleId = pickedObj.ElementId;
            Element ele = doc.GetElement(eleId);

            IEnumerable<Element> associatedElement = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Rebar)
                .Where(m => (m as FamilyInstance).Host.Id == eleId);

foreach (var item in associatedElement)
            {
                
                MessageBox.Show(item.get_Parameter(BuiltInParameter.REBAR_INSTANCE_BAR_DIAMETER).ToString());
            }

 where is the problem?

0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

Is the Host property set at all?

 

I don't know.

 

Have you checked that?

 

Have you installed and used RevitLookup?

 

What I meant was to use a solid intersection filter, cf. GetInstancesIntersectingElement:

 

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/C...

  

    #region Retrieve family instances intersecting BIM element
    /// <summary>
    /// Retrieve all family instances intersecting a
    /// given BIM element, e.g. all columns 
    /// intersecting a wall.
    /// </summary>
    void GetInstancesIntersectingElement( Element e )
    {
      Document doc = e.Document;

      Solid solid = e.get_Geometry( new Options() )
        .OfType<Solid>()
        .Where<Solid>( s => null != s && !s.Edges.IsEmpty )
        .FirstOrDefault();

      FilteredElementCollector intersectingInstances
        = new FilteredElementCollector( doc )
          .OfClass( typeof( FamilyInstance ) )
          .WherePasses( new ElementIntersectsSolidFilter(
            solid ) );

      int n1 = intersectingInstances.Count<Element>();

      intersectingInstances
        = new FilteredElementCollector( doc )
          .OfClass( typeof( FamilyInstance ) )
          .WherePasses( new ElementIntersectsElementFilter(
            e ) );

      int n = intersectingInstances.Count<Element>();

      Debug.Assert( n.Equals( n1 ),
        "expected solid intersection to equal element intersection" );

      string result = string.Format(
        "{0} family instance{1} intersect{2} the "
        + "selected element {3}{4}",
        n, Util.PluralSuffix( n ),
        ( 1 == n ? "s" : "" ),
        Util.ElementDescription( e ),
        Util.DotOrColon( n ) );

      string id_list = 0 == n
        ? string.Empty
        : string.Join( ", ",
            intersectingInstances
              .Select<Element, string>(
                x => x.Id.IntegerValue.ToString() ) )
          + ".";

      Util.InfoMsg2( result, id_list );
    }

    /// <summary>
    /// Retrieve all beam family instances 
    /// intersecting two columns, cf.
    /// http://forums.autodesk.com/t5/revit-api/check-to-see-if-beam-exists/m-p/6223562
    /// </summary>
    FilteredElementCollector
      GetBeamsIntersectingTwoColumns(
        Element column1,
        Element column2 )
    {
      Document doc = column1.Document;

      if( column2.Document.GetHashCode() != doc.GetHashCode() )
      {
        throw new ArgumentException(
          "Expected two columns from same document." );
      }

      FilteredElementCollector intersectingStructuralFramingElements
        = new FilteredElementCollector( doc )
          .OfClass( typeof( FamilyInstance ) )
          .OfCategory( BuiltInCategory.OST_StructuralFraming )
          .WherePasses( new ElementIntersectsElementFilter( column1 ) )
          .WherePasses( new ElementIntersectsElementFilter( column2 ) );

      int n = intersectingStructuralFramingElements.Count<Element>();

      string result = string.Format(
        "{0} structural framing family instance{1} "
        + "intersect{2} the two beams{3}",
        n, Util.PluralSuffix( n ),
        ( 1 == n ? "s" : "" ),
        Util.DotOrColon( n ) );

      string id_list = 0 == n
        ? string.Empty
        : string.Join( ", ",
            intersectingStructuralFramingElements
              .Select<Element, string>(
                x => x.Id.IntegerValue.ToString() ) )
          + ".";

      Util.InfoMsg2( result, id_list );

      return intersectingStructuralFramingElements;
    }
    #endregion // Retrieve family instances intersecting BIM element

  

Cheers,

  

Jeremy

  



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

Message 5 of 6

Einar_Raknes
Participant
Participant
Accepted solution

You can use the RebarHostData Class and the GetRebarsInHost Method to retrive all Rebars associated with a Rebar Host.

 

To make sure you pick a valid Rebar Host, you can create a selection filter: (optional step)

public class RebarHostSelectionFilter : ISelectionFilter
    {
        public bool AllowElement(Element element)
        {
            if (RebarHostData.GetRebarHostData(element) != null)
            {
                return true;
            }
            return false;
        }

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

And then pick a rebar host, and get a list of Rebars like this:

ref1 = uidoc.Selection.PickObject(ObjectType.Element, new RebarHostSelectionFilter(), "Pick a rebar host");
Element rebarHost = doc.GetElement(ref1)
IList<Rebar> rebarsInHost = RebarHostData.GetRebarHostData(rebarHost).GetRebarsInHost();
Message 6 of 6

jeremytammik
Autodesk
Autodesk

Many thanks to Einar for jumping in and coming to the rescue!

 

Preserved for posterity by The Building Coder:

 

https://thebuildingcoder.typepad.com/blog/2018/12/rebars-in-host-net-framework-and-importance-of-fuz...

 

Cheers,

 

Jeremy

 

 



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