Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding
Announcements
We are currently migrating data within this board to improve the community. During this process, posting, replying, editing and other features are temporarily disabled. We sincerely apologize for any inconvenience caused and appreciate your understanding. Thank you for your patience and support.

Get all associated Rebars which attach to the Structural Element

Anonymous
3,927 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?

 

Reply
Reply
0 Likes
Accepted solutions (1)
3,928 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

Reply
Reply
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?

Reply
Reply
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

Reply
Reply
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();
Reply
Reply
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

Reply
Reply