Add/Remove Host for a Rebar Bending Detail

Add/Remove Host for a Rebar Bending Detail

BertStragier4945
Contributor Contributor
856 Views
2 Replies
Message 1 of 3

Add/Remove Host for a Rebar Bending Detail

BertStragier4945
Contributor
Contributor

Anyone knows if there is solution through the Revit 2024 or 2025 API to simulate Add/Remove Host command for a Rebar Bending Detail?

I have a code to create a new Rebar Bending Detail for all my rebars in a specific host but I want to add identical Rebar sets all in one Bending Detail so I can use the 'Host Count'-parameter in my tag to have the right number instead of adding tags on every individual rebar.

0 Likes
857 Views
2 Replies
Replies (2)
Message 2 of 3

Moustafa_K
Advisor
Advisor

I think there is an access to that over here

 

I also believe on Revit 2025, they add the feature for adding multiple hosts

RebarBendingDetail.AddHosts(Element bendingDetail, IList<Reference> references)

 is that what you are looking for

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 3 of 3

BertStragier4945
Contributor
Contributor

Hi @Moustafa_K,

thanks already for your help!

I still have some issues with the references. When I use my Add-in in Revit2025 I receive the following error: 

BertStragier4945_0-1718694829307.png

 

This is a part of my code where I implemented the RebarBendingDetail.AddHosts on line 75:

IList<Reference> rebarRefs = new List<Reference>();

// Place rebar bending detail for all rebars with style Standard
for (int i = 0; i < RebarsStandard.Count; i++)
{
    Element rebarElem = RebarsStandard[i];
    Rebar rebarStandard = rebarElem as Rebar;

    using (Transaction trans = new Transaction(doc, "Add Rebar Bending Detail"))
    {
        trans.Start();

        // Search for the right Rebar Bending Detail Type
        RebarBendingDetailType rebarBendingDetailType = null;
        {
            var collectorRebarBendingDetail = new FilteredElementCollector(doc);
            var detailTypes = collectorRebarBendingDetail.OfClass(typeof(RebarBendingDetailType)).Cast<RebarBendingDetailType>();

            Parameter rebarShapeParameter = rebarStandard.get_Parameter(BuiltInParameter.REBAR_SHAPE);
            Element rebarShape = doc.GetElement(rebarShapeParameter.AsElementId());
            string shapeCode = rebarShape.Name;

            foreach (var type in detailTypes)
            {
                if (shapeCode == "00")
                {
                    if (type.Name == "Bending Detail - Longitudanal Straight Rebars")
                    {
                        rebarBendingDetailType = type;
                        break;
                    }
                }
                else
                {
                    if (type.Name == "Bending Detail - Longitudanal Bended Rebars")
                    {
                        rebarBendingDetailType = type;
                        break;
                    }
                }
            }

            if (rebarBendingDetailType == null)
            {
                TaskDialog.Show("Error", "Rebar Bending Detail type not found.");
                trans.RollBack();
                return;
            }

            // Choose the selected number of rebars in the detail
            int numberOfRebars = 1;

            // Choose the rotation of the detail
            double rotation = 0.0; // In radians


            // Create Rebar Bending Detail if middle rebars are needed
            if (RebarsStandard.Count > 2)
            {
                if (i != 0 && i != (RebarsStandard.Count - 1) && i != (RebarsStandard.Count - 2))
                {
                    rebarRefs.Add(new Reference (rebarStandard));
                }
            }

            // Create Rebar Bending Detail if middle rebars are needed
            if (RebarsStandard.Count > 1)
            {
                if (i == (RebarsStandard.Count - 2))
                {
                    // Make a new location for RebarBendingDetail
                    XYZ newLocationDetail = ((vertex1 + vertex2) * 0.5) + (XYZ.BasisZ * heightParam) + ((vertex1 - vertex2).Normalize() * (55 / 30.48)) + (XYZ.BasisZ * (15 / 30.48));

                    var bendingDetail = RebarBendingDetail.Create(doc, doc.ActiveView.Id, rebarStandard.Id, numberOfRebars, rebarBendingDetailType, newLocationDetail, rotation);
                    RebarBendingDetail.AddHosts(bendingDetailElem, rebarRefs);
                }
            }
        }
        trans.Commit();

 

0 Likes