/// <summary> /// Get the swept profile(face) of the host object(family instance) /// </summary> /// <param name="solid">the solid reference</param> /// <returns>the swept profile</returns> private Face GetSweptProfileFace(Solid solid) { // Get a point on the swept profile from all points in solid Autodesk.Revit.DB.XYZ refPoint = new Autodesk.Revit.DB.XYZ(); // the point on swept profile foreach (Edge edge in solid.Edges) { List <XYZ> points = edge.Tessellate() as List <XYZ>; //get end points of the edge if (2 != points.Count) // make sure all edges are lines { throw new Exception("All edge should be line."); } // get two points of the edge. All points in solid should be transform first Autodesk.Revit.DB.XYZ first = Transform(points[0]); // start point of edge Autodesk.Revit.DB.XYZ second = Transform(points[1]); // end point of edge // some edges should be parallelled with the driving line, // and the start point of that edge should be the wanted point Autodesk.Revit.DB.XYZ edgeVector = GeomUtil.SubXYZ(second, first); if (GeomUtil.IsSameDirection(edgeVector, m_drivingVector)) { refPoint = first; break; } if (GeomUtil.IsOppositeDirection(edgeVector, m_drivingVector)) { refPoint = second; break; } } // Find swept profile(face) Face sweptFace = null; // define the swept face foreach (Face face in solid.Faces) { if (null != sweptFace) { break; } // the swept face should be perpendicular with the driving line if (!GeomUtil.IsVertical(face, m_drivingLine, m_transform, null)) { continue; } // use the gotted point to get the swept face foreach (Autodesk.Revit.DB.XYZ point in face.Triangulate().Vertices) { Autodesk.Revit.DB.XYZ pnt = Transform(point); // all points in solid should be transform if (GeomUtil.IsEqual(refPoint, pnt)) { sweptFace = face; break; } } } return(sweptFace); }
/// <summary> /// get the orient of hook accroding to curve direction, rebar normal and hook direction /// </summary> /// <param name="curveVec">the curve direction</param> /// <param name="normal">rebar normal direction</param> /// <param name="hookVec">the hook direction</param> /// <returns>the orient of the hook</returns> public static RebarHookOrientation GetHookOrient(Autodesk.Revit.DB.XYZ curveVec, Autodesk.Revit.DB.XYZ normal, Autodesk.Revit.DB.XYZ hookVec) { Autodesk.Revit.DB.XYZ tempVec = normal; for (int i = 0; i < 4; i++) { tempVec = GeomUtil.CrossMatrix(tempVec, curveVec); if (GeomUtil.IsSameDirection(tempVec, hookVec)) { if (i == 0) { return(RebarHookOrientation.Right); } else if (i == 2) { return(RebarHookOrientation.Left); } } } throw new Exception("Can't find the hook orient according to hook direction."); }