Revit API:钢筋容器完全放置在其宿主之外

Revit API: Rebar Container is placed completely outside of its host

当我尝试创建钢筋容器时,我在 运行:

之后在 Revit 中收到此错误

Warning - can be ignored

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

我不知道该如何避免这个错误。这是代码:

containertype = RebarContainerType.
                GetOrCreateRebarContainerType(Doc, "myContainer");
container = RebarContainer.Create(Doc, hostObject, containertype);

每个 RebarContainer 都包含 RebarContainerItem 对象的集合(首次创建时为空)。 RebarContainerItem 提供类似于 Rebar 元素的属性和方法。

你可以使用静态方法

 RebarContainer.Create() 

这需要您要在其中创建新 RebarContainer 的文档、将托管新 RebarContainer 的宿主元素以及将分配给新 RebarContainer 的 RebarContainerType 的 ElementId。

这是创建钢筋容器的代码。

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);
 }
}

请原谅我糟糕的代码格式。这是我在 Stack overflow 中的第一个 post :)