本人在开发时,调用扫略放样建模时,出现了几次创建出来的模型扭曲,轮廓被旋转,和期望严重不符的情形。
尽管路径曲线和轮廓线看起来是一样的,某些情形下,总是得到不一致的结果。查找资料后,发现是因为路径的草图平面不同导致的。即:放样时,同样的路径和轮廓,当路径的草图平面不同时,可能会得到不同的结果。
下面给出一个简单的实例,图中两个立方体,是下面的代码创建的。注意,在这段代码中,轮廓线和路径都是一样的,只是路径的草图平面不同,生成的模型就不一样。
我想,这足以说明问题了。希望对遇到此问题的程序猿有所帮助。
//创建两个放样模型,在族编辑器环境中运行
public void CreateSweep(Document m_rvtDoc)
{
Transaction trans = new Transaction(m_rvtDoc, "Sweep");
trans.Start();
SweepProfile profile = CreateSweepProfile(m_rvtDoc);
//1. 路径的草图平面是xz-plane
//Plane(normal, origin)
Plane plane1 = Plane.CreateByNormalAndOrigin(XYZ.BasisY, new XYZ(0, 0, 0));
SketchPlane sketchPlane1 = SketchPlane.Create(m_rvtDoc, plane1);
Line line1 = Line.CreateBound(XYZ.Zero, new XYZ(0, 0, 100));
ModelCurve mLine1 = m_rvtDoc.FamilyCreate.NewModelCurve(line1, sketchPlane1);
CurveArray pathArray1 = new CurveArray();
pathArray1.Append(line1);
m_rvtDoc.FamilyCreate.NewSweep(true, pathArray1, sketchPlane1, profile, 0, ProfilePlaneLocation.Start);
//2. 路径平面是yz-plane
Plane plane2 = Plane.CreateByNormalAndOrigin(XYZ.BasisX, new XYZ(0, 0, 0));
SketchPlane sketchPlane2 = SketchPlane.Create(m_rvtDoc, plane2);
Line line2 = Line.CreateBound(XYZ.Zero, new XYZ(0, 0, 200));
ModelCurve mLine2 = m_rvtDoc.FamilyCreate.NewModelCurve(line2, sketchPlane2);
CurveArray pathArray2 = new CurveArray();
pathArray2.Append(line2);
m_rvtDoc.FamilyCreate.NewSweep(true, pathArray2, sketchPlane2, profile, 0, ProfilePlaneLocation.Start);
trans.Commit();
}
private SweepProfile CreateSweepProfile(Document doc)
{
XYZ pt1 = new XYZ(0, 0, 0);
XYZ pt2 = new XYZ(10, 0, 0);
XYZ pt3 = new XYZ(10, 20, 0);
XYZ pt4 = new XYZ(0, 20, 0);
Line line1 = Line.CreateBound(pt1, pt2);
Line line2 = Line.CreateBound(pt2, pt3);
Line line3 = Line.CreateBound(pt3, pt4);
Line line4 = Line.CreateBound(pt4, pt1);
CurveArray curArray = new CurveArray();
curArray.Append(line1);
curArray.Append(line2);
curArray.Append(line3);
curArray.Append(line4);
CurveArrArray curArrArray = new CurveArrArray();
curArrArray.Append(curArray);
SweepProfile spf_0 = doc.Application.Create.NewCurveLoopsProfile(curArrArray);
return spf_0;
}