0

When I try to create a rebar container I get this error inside Revit after running:

Warning - can be ignored

"Rebar Container is placed completely outside of its host."

I don't know how should I avoid this error. Here is the code:

containertype = RebarContainerType.
                GetOrCreateRebarContainerType(Doc, "myContainer");
container = RebarContainer.Create(Doc, hostObject, containertype);
Saeid
  • 691
  • 7
  • 26

1 Answers1

1

Each RebarContainer contains a collection (empty when first created) of RebarContainerItem objects. RebarContainerItem provides properties and methods similar to that of a Rebar element.

You may use the static method

 RebarContainer.Create() 

which requires the Document in which you want to create a new RebarContainer, the host Element which will host the new RebarContainer and the ElementId of the RebarContainerType which will be assigned to the new RebarContainer.

Here is the code in order to create a rebar Container.

void AddItemsToRebarContainer(RebarContainer container, FamilyInstance beam, 
                              RebarBarType barType, RebarHookType hookType)
{
   // Define the rebar geometry information - Line rebar
   LocationCurve location = beam.Location as LocationCurve;
   XYZ origin = location.Curve.GetEndPoint(0);

   // create rebar along the length of the beam
   XYZ rebarLineEnd = location.Curve.GetEndPoint(1);
   Line line = Line.CreateBound(origin, rebarLineEnd);
   XYZ normal = new XYZ(1, 0, 0);
   Curve rebarLine = line.CreateOffset(0.5, normal);

   // Create the line rebar
   IList<Curve> curves = new List<Curve>();
   curves.Add(rebarLine);

   RebarContainerItem item = container.AppendItemFromCurves
   (RebarStyle.Standard, barType, hookType, hookType, normal, 
   curves, RebarHookOrientation.Right, RebarHookOrientation.Left, true, true);

if (null != item)
 {
    // set specific layout for new rebar as fixed number, with 10 bars, 
    // distribution path length of 1.5'
    // with bars of the bar set on the same side of the rebar plane as 
    // indicated by normal and both first and last bar in the set are shown

    item.SetLayoutAsFixedNumber(10, 1.5, true, true, true);
 }
}

Forgive me for my poor code formatting. It is my first post in Stack overflow :)

Jaime Rosales
  • 1,106
  • 1
  • 6
  • 8