前言
这个例子介绍了如何创建拉伸、放样、扫掠、融合、放样融合,涵盖了一个建模软件需要的基本建模方法。
内容
CreateExtrusion
生成的放样融合接口:
m_creationFamily.NewExtrusion(true, curve, sketchPlane, bottomProfile, topProfile)
核心逻辑:
// 创建工作平面
Autodesk.Revit.DB.XYZ normal = Autodesk.Revit.DB.XYZ.BasisZ;
SketchPlane sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero);
// 创建矩形轮廓
curveArrArray = new CurveArrArray();
CurveArray curveArray1 = new CurveArray();
Autodesk.Revit.DB.XYZ p0 = Autodesk.Revit.DB.XYZ.Zero;
Autodesk.Revit.DB.XYZ p1 = new Autodesk.Revit.DB.XYZ(10, 0, 0);
Autodesk.Revit.DB.XYZ p2 = new Autodesk.Revit.DB.XYZ(10, 10, 0);
Autodesk.Revit.DB.XYZ p3 = new Autodesk.Revit.DB.XYZ(0, 10, 0);
Line line1 = Line.CreateBound(p0, p1);
Line line2 = Line.CreateBound(p1, p2);
Line line3 = Line.CreateBound(p2, p3);
Line line4 = Line.CreateBound(p3, p0);
curveArray1.Append(line1);
curveArray1.Append(line2);
curveArray1.Append(line3);
curveArray1.Append(line4);
curveArrArray.Append(curveArray1);
// 创建拉伸体
Extrusion rectExtrusion = m_creationFamily.NewExtrusion(true, curveArrArray, sketchPlane, 10);
CreateSweep
生成的扫掠体接口:
m_creationFamily.NewSweep(true, curves, sketchPlane, profile, 0, ProfilePlaneLocation.Start)
核心逻辑:
// 创建工作平面
Autodesk.Revit.DB.XYZ normal = Autodesk.Revit.DB.XYZ.BasisZ;
SketchPlane sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero);
// 创建圆形轮廓
CurveArrArray arrarr = new CurveArrArray();
CurveArray arr = new CurveArray();
Autodesk.Revit.DB.XYZ pnt1 = new Autodesk.Revit.DB.XYZ(0, 0, 0);
Autodesk.Revit.DB.XYZ pnt2 = new Autodesk.Revit.DB.XYZ(2, 0, 0);
Autodesk.Revit.DB.XYZ pnt3 = new Autodesk.Revit.DB.XYZ(1, 1, 0);
arr.Append(Arc.Create(pnt2, 1.0d, 0.0d, 180.0d, Autodesk.Revit.DB.XYZ.BasisX, Autodesk.Revit.DB.XYZ.BasisY));
arr.Append(Arc.Create(pnt1, pnt3, pnt2));
arrarr.Append(arr);
SweepProfile profile = m_revit.Create.NewCurveLoopsProfile(arrarr);
// 创建扫掠路径
Autodesk.Revit.DB.XYZ pnt4 = new Autodesk.Revit.DB.XYZ(10, 0, 0);
Autodesk.Revit.DB.XYZ pnt5 = new Autodesk.Revit.DB.XYZ(0, 10, 0);
Curve curve = Line.CreateBound(pnt4, pnt5);
CurveArray curves = new CurveArray();
curves.Append(curve);
// 创建扫掠体
Sweep sweep1 = m_creationFamily.NewSweep(true, curves, sketchPlane, profile, 0, ProfilePlaneLocation.Start);
CreateRevolution
生成的旋转体接口:
m_creationFamily.NewRevolution(true, curveArrArray, sketchPlane, axis1, -Math.PI, 0);
核心逻辑:
// 创建工作平面
Autodesk.Revit.DB.XYZ normal = Autodesk.Revit.DB.XYZ.BasisZ;
SketchPlane sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero);
// 创建矩形轮廓
CurveArrArray curveArrArray = new CurveArrArray();
CurveArray curveArray = new CurveArray();
Autodesk.Revit.DB.XYZ p0 = Autodesk.Revit.DB.XYZ.Zero;
Autodesk.Revit.DB.XYZ p1 = new Autodesk.Revit.DB.XYZ(10, 0, 0);
Autodesk.Revit.DB.XYZ p2 = new Autodesk.Revit.DB.XYZ(10, 10, 0);
Autodesk.Revit.DB.XYZ p3 = new Autodesk.Revit.DB.XYZ(0, 10, 0);
Line line1 = Line.CreateBound(p0, p1);
Line line2 = Line.CreateBound(p1, p2);
Line line3 = Line.CreateBound(p2, p3);
Line line4 = Line.CreateBound(p3, p0);
curveArray.Append(line1);
curveArray.Append(line2);
curveArray.Append(line3);
curveArray.Append(line4);
curveArrArray.Append(curveArray);
// 创建旋转轴
Autodesk.Revit.DB.XYZ pp = new Autodesk.Revit.DB.XYZ(1, -1, 0);
Line axis1 = Line.CreateBound(Autodesk.Revit.DB.XYZ.Zero, pp);
// 生成旋转体
Revolution revolution1 = m_creationFamily.NewRevolution(true, curveArrArray, sketchPlane, axis1, -Math.PI, 0);
CreateBlend
生成的融合体接口:
m_creationFamily.NewBlend(true, topProfile, baseProfile, sketchPlane);
核心逻辑:
// 创建工作平面
Autodesk.Revit.DB.XYZ normal = Autodesk.Revit.DB.XYZ.BasisZ;
SketchPlane sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero);
// 创建顶部轮廓
CurveArray topProfile = new CurveArray();
Autodesk.Revit.DB.XYZ p10 = new Autodesk.Revit.DB.XYZ(5, 2, 10);
Autodesk.Revit.DB.XYZ p11 = new Autodesk.Revit.DB.XYZ(8, 5, 10);
Autodesk.Revit.DB.XYZ p12 = new Autodesk.Revit.DB.XYZ(5, 8, 10);
Autodesk.Revit.DB.XYZ p13 = new Autodesk.Revit.DB.XYZ(2, 5, 10);
Line line11 = Line.CreateBound(p10, p11);
Line line12 = Line.CreateBound(p11, p12);
Line line13 = Line.CreateBound(p12, p13);
Line line14 = Line.CreateBound(p13, p10);
topProfile.Append(line11);
topProfile.Append(line12);
topProfile.Append(line13);
topProfile.Append(line14);
// 创建底部轮廓
CurveArray baseProfile = new CurveArray();
Autodesk.Revit.DB.XYZ p00 = Autodesk.Revit.DB.XYZ.Zero;
Autodesk.Revit.DB.XYZ p01 = new Autodesk.Revit.DB.XYZ(10, 0, 0);
Autodesk.Revit.DB.XYZ p02 = new Autodesk.Revit.DB.XYZ(10, 10, 0);
Autodesk.Revit.DB.XYZ p03 = new Autodesk.Revit.DB.XYZ(0, 10, 0);
Line line01 = Line.CreateBound(p00, p01);
Line line02 = Line.CreateBound(p01, p02);
Line line03 = Line.CreateBound(p02, p03);
Line line04 = Line.CreateBound(p03, p00);
baseProfile.Append(line01);
baseProfile.Append(line02);
baseProfile.Append(line03);
baseProfile.Append(line04);
// 创建融合体
Blend blend = m_creationFamily.NewBlend(true, topProfile, baseProfile, sketchPlane);
CreateSweptBlend
生成扫掠融合体接口:
m_creationFamily.NewSweptBlend(true, curve, sketchPlane, bottomProfile, topProfile);
核心逻辑:
// 创建工作平面
Autodesk.Revit.DB.XYZ normal = Autodesk.Revit.DB.XYZ.BasisZ;
SketchPlane sketchPlane = CreateSketchPlane(normal, Autodesk.Revit.DB.XYZ.Zero);
// 创建底部轮廓
Autodesk.Revit.DB.XYZ pnt1 = new Autodesk.Revit.DB.XYZ(0, 0, 0);
Autodesk.Revit.DB.XYZ pnt2 = new Autodesk.Revit.DB.XYZ(1, 0, 0);
Autodesk.Revit.DB.XYZ pnt3 = new Autodesk.Revit.DB.XYZ(1, 1, 0);
Autodesk.Revit.DB.XYZ pnt4 = new Autodesk.Revit.DB.XYZ(0, 1, 0);
Autodesk.Revit.DB.XYZ pnt5 = new Autodesk.Revit.DB.XYZ(0, 0, 1);
CurveArrArray arrarr1 = new CurveArrArray();
CurveArray arr1 = new CurveArray();
arr1.Append(Line.CreateBound(pnt1, pnt2));
arr1.Append(Line.CreateBound(pnt2, pnt3));
arr1.Append(Line.CreateBound(pnt3, pnt4));
arr1.Append(Line.CreateBound(pnt4, pnt1));
arrarr1.Append(arr1);
SweepProfile bottomProfile = m_revit.Create.NewCurveLoopsProfile(arrarr1);
// 创建顶部轮廓
Autodesk.Revit.DB.XYZ pnt6 = new Autodesk.Revit.DB.XYZ(0.5, 0, 0);
Autodesk.Revit.DB.XYZ pnt7 = new Autodesk.Revit.DB.XYZ(1, 0.5, 0);
Autodesk.Revit.DB.XYZ pnt8 = new Autodesk.Revit.DB.XYZ(0.5, 1, 0);
Autodesk.Revit.DB.XYZ pnt9 = new Autodesk.Revit.DB.XYZ(0, 0.5, 0);
CurveArrArray arrarr2 = new CurveArrArray();
CurveArray arr2 = new CurveArray();
arr2.Append(Line.CreateBound(pnt6, pnt7));
arr2.Append(Line.CreateBound(pnt7, pnt8));
arr2.Append(Line.CreateBound(pnt8, pnt9));
arr2.Append(Line.CreateBound(pnt9, pnt6));
arrarr2.Append(arr2);
SweepProfile topProfile = m_revit.Create.NewCurveLoopsProfile(arrarr2);
// 创建扫掠线
Autodesk.Revit.DB.XYZ pnt10 = new Autodesk.Revit.DB.XYZ(5, 0, 0);
Autodesk.Revit.DB.XYZ pnt11 = new Autodesk.Revit.DB.XYZ(0, 20, 0);
Curve curve = Line.CreateBound(pnt10, pnt11);
// 生成扫掠融合
SweptBlend newSweptBlend1 = m_creationFamily.NewSweptBlend(true, curve, sketchPlane, bottomProfile, topProfile);