-1

1- How can I find the angle for sloped wall in the x,y.I used the code below to find it for the walls but it didn't work for sloped wall. When I use it for the ordinary walls it gives XYz like 0,1,0/0,-1,0/1,0,0/-1,0,0 but for the sloped wall it become 0,0,1 all the time. Please, read the code. 2- I want to find the wall Id for the windows and doors in my Revit project using the API. I can find the openings in the wall but what I actually need is quite the opposite, I need the host.

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;

    }
uakam
  • 27
  • 6

1 Answers1

0

You'll need to get all elements where the HOST_ID_PARAM equals the Wall ID you have. Here is an example. Below is a minimum version of it.

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)
  {

  }
}
Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44