Rebar host face numbers

Rebar host face numbers

Anonymous
Not applicable
840 Views
3 Replies
Message 1 of 4

Rebar host face numbers

Anonymous
Not applicable

Hi everyone

 

In my company we make a lot of prestressed elements.
The rebars in these elements are not governed by their cover, but by the prestressed strands going through the beam which they are tied to.

Since Revit rebar is controlled by the concrete host covers we have set up some calculations on our strand patterns that can tell the user what to input as the cover on each face of the beam. (picture 1) in order to get the correct size to match the strandpattern. This workflow works great, but takes a long time for the users to perform.

 

if i click edit constraints on a specific rebar => click on a section of a bar => and hover my mouse over the sections constraint surface i get a face number. (picture 2 and 3)

 

This face number could be super useful for saving and applying cover settings, but i am unable to find the face number via the API. I can get the face reference, and set new cover types to those faces, but i am doing it all without knowing which face i am interacting with.

The ID number is just the id of the host. and i cant find the face number on the geometry object.

I tryed getting a collection of faces and then using the face number as index but that didnt work.

 

the code below will set all faces in the element to the cover "aggressiv"  but i want to store a face number and the cover setting, and then reapply it to other beams in other projects.

 

Any help in finding the face number is greatly appriciated.

 

KB section.PNG

edit constraints.png

edit constraints zoom.PNG

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;


using EventLog = CRH.Core.EventLog.EventLog;
using CRH.Functions;

namespace CRH.Functions
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    class RebarSniffer : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;

            if (doc.IsFamilyDocument)
            {
                TaskDialog.Show("Error", "This is a family document");
                return Result.Cancelled;
            }

            FilteredElementCollector fecRebar =
                new FilteredElementCollector(doc)
                .OfCategory(BuiltInCategory.OST_Rebar)
                .OfClass(typeof(Rebar));

            Rebar rebarInstance = (Rebar)fecRebar.FirstElement();

            List<Reference> references = new List<Reference>();
            ElementId host = rebarInstance.GetHostId();
            FamilyInstance beam = (FamilyInstance)doc.GetElement(host);

            Options options = new Options();
            options.ComputeReferences = true;
            options.IncludeNonVisibleObjects = true;

            GeometryElement geometryElement = beam.get_Geometry(options);

            foreach (GeometryObject geoObj in geometryElement)
            {
                if (geoObj is Solid)
                {
                    Solid solid = (Solid)geoObj;
                    if (solid.Faces.Size > 1)
                    {
                        foreach (Face face in solid.Faces)
                        {
                            //foreach (Face face in faceArray)
                            {
                                references.Add(face.Reference);

                            }
                        }
                    }
                }
            }

            RebarHostData rebarHostData = RebarHostData.GetRebarHostData(beam);

            FilteredElementCollector fecCoverTypes =
                new FilteredElementCollector(doc)
                .OfCategory(BuiltInCategory.OST_CoverType);

            RebarCoverType cover = null;

            foreach (RebarCoverType rebarCoverType in fecCoverTypes)
            {
                if (rebarCoverType.Name.Equals("Aggressiv"))
                {
                    cover = rebarCoverType;
                    break;
                }

            }

            using (Transaction t = new Transaction(doc, "Setting rebar"))
            {
                t.Start();
                string surface = ":SURFACE";
                List<string> guids = new List<string>();
                foreach (Reference reference in references)
                {
                    //string MaybeFaceNumber = reference.ConvertToStableRepresentation(doc);
                    //// a5ab46d4-bff6-4c2f-9545-93b69f55c39f-00150444:22:SURFACE
                    //if (MaybeFaceNumber.EndsWith("22" + surface) || MaybeFaceNumber.EndsWith("26" + surface) || MaybeFaceNumber.EndsWith("34" + surface) || MaybeFaceNumber.EndsWith("30" + surface))
                    {

                        rebarHostData.SetCoverType(reference, cover);

                    }
                }

                t.Commit();
            }
            return Result.Succeeded;
        }
    }
}
0 Likes
841 Views
3 Replies
Replies (3)
Message 2 of 4

corinne.astori
Advocate
Advocate

Hi T_Koppel,

I don't have a concrete answer but I know that the RebarHostData class has a method that get all the exposed faces (RebarHostData.GetExposedFaces()). These are probably the faces you are looking for. But honestly I don't know how to get their number.

Regards,

Corinne

0 Likes
Message 3 of 4

corinne.astori
Advocate
Advocate

Maybe the class RebarConstraint could be usefull for your purpose as it has a method called RebarConstraint.GetTargetHostFaceReference (with one overload), wich already gives you the right face, then you don't need the number of the face anymore.

Let us know if you can solve your issue and if these methods were usefull.

Regards

Corinne

 
 
0 Likes
Message 4 of 4

kailas_dhage
Contributor
Contributor

If we know the face reference then we can easily determine it plane and this plane again can be matched with one the family instance faces. 

Following routine determines face reference and its associated plane.

 

Hope it will helpful to find actual instance face from it.

 

 

public static Dictionary<Reference, Plane> GetExposedFaceReferencePlaneMap(Element ent)
        {
            var faceDict = new Dictionary<Reference, Plane>();
            var rebarHostData = RebarHostData.GetRebarHostData(ent);
            if (rebarHostData == null)
            {
                return faceDict;
            }

            var faces = rebarHostData.GetExposedFaces();
            using (var trans = new Transaction(ent.Document, "IMPACT Face Plane Map"))
            {
                trans.Start();
                foreach (var face in faces)
                {
                    try
                    {
                        var sk = SketchPlane.Create(ent.Document, face);
                        if (null != sk)
                        {
                            faceDict[face] = sk.GetPlane();
                        }
                    }
                    catch
                    {
                        //
                    }
                }

                trans.RollBack();
            }

            return faceDict;
        }
0 Likes