倾斜的墙壁方向和门窗的主机Revit API

本文关键字:主机 API Revit 方向 倾斜 | 更新日期: 2023-09-27 17:55:39

1- 如何在 x,y 中找到倾斜墙的角度.我使用下面的代码为墙壁找到它,但它不适用于倾斜墙。当我将其用于普通墙壁时,它会给出 XYz 如 0,1,0/0,-1,0/1,0,0/-1,0,0,0但是对于倾斜的墙壁,它一直变成 0,0,1。请阅读代码。 2-我想使用接口。我可以在墙上找到开口,但我实际需要的是恰恰相反,我需要主人。

protected XYZ GetExteriorWallDirection(Element wall)
    {
        LocationCurve locationCurve 
          = wall.Location as LocationCurve;
        XYZ exteriorDirection = XYZ.BasisZ;
        if (locationCurve != null)
        {
            Curve curve = locationCurve.Curve;
            //Write("Wall line endpoints: ", curve);
            XYZ direction = XYZ.BasisX;
            if (curve is Line)
            {
                // Obtains the tangent vector of the wall.
                direction = curve.ComputeDerivatives(
                  0, true).BasisX.Normalize();
            }
            else
            {

                // An assumption, for non-linear walls, 
                // that the "tangent vector" is the direction
                // from the start of the wall to the end.
                direction = (curve.GetEndPoint(1)
                  - curve.GetEndPoint(0)).Normalize();
            }
            // Calculate the normal vector via cross product.
            exteriorDirection = getCrossProduct(XYZ.BasisZ,direction);
            // Flipped walls need to reverse the calculated direction
            Wall wa = wall as Wall;
            if (wa.Flipped)
            {
                exteriorDirection = -exteriorDirection;
            }
        }
        return exteriorDirection;
    }

protected XYZ getCrossProduct(XYZ a, XYZ b)
    {
        double ax = a.X;
        double ay = a.Y;
        double az = a.Z;
        double bx = b.X;
        double by = b.Y;
        double bz = b.Z;

        double cx = ay * bz - az * by;//= 3×7 − 4×6 = −3
        double cy = az * bx - ax * bz;//= 4×5 − 2×7 = 6
        double cz = ax * by - ay * bx;// = 2×6 − 3×5 = −3

        XYZ c = new XYZ(cx, cy, cz);
        return c;
    }

倾斜的墙壁方向和门窗的主机Revit API

您需要

获取HOST_ID_PARAM等于您拥有的 Wall ID 的所有元素。下面是一个示例。下面是它的最低版本。

private static void HostedFamilyInstanceOpenings(Wall wall)
{
  // Filter all Family Instances where the HOST_ID_PARAM 
  // equals the wall ID
  // 
  // More information at
  // http://thebuildingcoder.typepad.com/
  //                 blog/2010/06/parameter-filter.html#4
  BuiltInParameter testParam =
      BuiltInParameter.HOST_ID_PARAM;
  ParameterValueProvider pvp =
      new ParameterValueProvider(
          new ElementId((int)testParam));
  FilterNumericRuleEvaluator fnrv = new FilterNumericEquals();
  ElementId ruleValId = wall.Id;
  FilterRule paramFr = new FilterElementIdRule
    (pvp, fnrv, ruleValId);
  ElementParameterFilter epf = 
    new ElementParameterFilter(paramFr);
  FilteredElementCollector collector =
      new FilteredElementCollector(wall.Document);
  collector.OfClass(typeof(FamilyInstance)).WherePasses(epf);
  IList<Element> hostedFamilyInstances = collector.ToElements();
  // Now iterate through the collected family instances  
  foreach (FamilyInstance instance in hostedFamilyInstances)
  {
  }
}