FamilyItemFactory族组件工厂之体量的创建(Revit二次开发)

首先说一下Revit体量里的放样都有哪些api:
1、通过轮廓和方向生成几何体 (拉伸操作)
Form NewExtrusionForm(bool isSolid, ReferenceArray profile, DB.XYZ direction);
2、通过轮廓线生成面 (融合操作)
Form NewFormByCap(bool isSolid, ReferenceArray profile);
3、通过面和向量生成体 (旋转操作)
Form NewFormByThickenSingleSurface(bool isSolid, Form singleSurfaceForm, DB.XYZ thickenDir);
4、通过轮廓组生成体 (放样操作)
Form NewLoftForm(bool isSolid, ReferenceArrayArray profiles);
5、通过放样路径和轮廓组生成几何体 (放样融合操作)
Form NewSweptBlendForm(bool isSolid, ReferenceArray path, ReferenceArrayArray profiles);

示例一:
使用NewSweep来根据某条曲线的路径生成对应截面的体量模型。

Sweep NewSweep(bool isSolid,CurveArray path,SketchPlane pathPlane,SweepProfile profile,int profileLocationCurveIndex,ProfilePlaneLocation profilePlaneLocation)

参数说明:

  1. isSolid
    类型: System布尔值
    指示放样是“实心”还是“空心”。
  2. 路径
    类型: Autodesk.Revit.DB CurveArray
    生成的路径。路径应为2D,其中所有输入曲线都位于一个平面上,并且不需要曲线来引用现有几何图形。
  3. 路径平面
    类型: Autodesk.Revit.DB SketchPlane
    路径的草图平面。
  4. 轮廓
    类型: Autodesk.Revit.DB SweepProfile
    它可能包含多个曲线环或一个轮廓族。轮廓必须位于XY平面中,并且它将自动转换为轮廓平面。每个回路必须是完全闭合的曲线回路,并且回路不得相交。循环可以是未绑定的圆形或椭圆形,但是其几何形状将分为两部分,以满足对拉伸中使用的草图的要求。
  5. profileLocationCurveIndex
    类型: System Int32
    路径曲线的索引。
  6. profilePlaneLocation
    类型: Autodesk.Revit.DB ProfilePlaneLocation
    profileLocationCurve上确定轮廓平面的位置。

方法示例:

        private Sweep CreateSweep(Autodesk.Revit.DB.Document document, SketchPlane sketchPlane)
        {
            Sweep sweep = null;
            // 确保我们有一个族文件
            if (true == document.IsFamilyDocument)
            {
                // 为实体定义一个轮廓
                CurveArrArray arrarr = new CurveArrArray();
                CurveArray arr = new CurveArray();

                // 创建椭圆形轮廓
                XYZ pnt1 = new XYZ(0, 0, 0);
                XYZ pnt2 = new XYZ(2, 0, 0);
                XYZ pnt3 = new XYZ(1, 1, 0);
                arr.Append(Arc.Create(pnt2, 1.0d, 0.0d, 180.0d, XYZ.BasisX, XYZ.BasisY));
                arr.Append(Arc.Create(pnt1, pnt3, pnt2));
                arrarr.Append(arr);
                SweepProfile profile = document.Application.Create.NewCurveLoopsProfile(arrarr);

                // 为实体定义一个路径
                XYZ pnt4 = new XYZ(10, 0, 0);
                XYZ pnt5 = new XYZ(0, 10, 0);
                Curve curve = Line.CreateBound(pnt4, pnt5);
                CurveArray curves = new CurveArray();
                curves.Append(curve);

                // 创建实心椭圆形体量
                sweep = document.FamilyCreate.NewSweep(true, curves, sketchPlane, profile, 0, ProfilePlaneLocation.Start);

                if (null != sweep)
                {
                    // 移到适当的地方
                    XYZ transPoint1 = new XYZ(11, 0, 0);
                    ElementTransformUtils.MoveElement(document, sweep.Id, transPoint1);
                }
                else
                {
                    throw new Exception("创建实体失败");
                }
            }
            else
            {
                throw new Exception("请在调用此命令之前打开一个族文件");
            }

            return sweep;
        }

示例二:
使用NewSweptBlend来根据某条曲线的路径生成对应截面的体量模型。

SweptBlend NewSweptBlend(bool isSolid,Curve path,SketchPlane pathPlane,SweepProfile bottomProfile,SweepProfile topProfile)

参数说明:

  1. isSolid
    类型: System布尔值
    指示放样模型是“实心”还是“虚心”。
  2. 路径
    类型: Autodesk.Revit.DB Curve
    放样模型的路径。路径应该是一条曲线。或者,路径可以是一条草绘曲线,并且该曲线不需要引用现有几何图形。
  3. 路径平面
    类型: Autodesk.Revit.DB SketchPlane
    路径的草图平面。当您要创建位于现有平面上的2D路径时,使用此选项。可以是从几何图形获得的曲线,或引用的曲线 。
  4. bottomProfile
    类型: Autodesk.Revit.DB SweepProfile
    放样模型的底部形状。它应该是一个曲线环。轮廓必须位于XY平面中。
  5. topProfile
    类型: Autodesk.Revit.DB SweepProfile
    放样模型的顶部形状。它应该是一个曲线环。轮廓必须位于XY平面中。

方法示例:

private SweptBlend CreateSweptBlend(Autodesk.Revit.DB.Document document, SketchPlane sketchPlane)
        {
            SweptBlend newSweptBlend = null;
            // 确保我们有一个族文件
            if (true == document.IsFamilyDocument)
            {
                // 创建顶部和底部轮廓以及路径曲线
                XYZ pnt1 = new XYZ(0, 0, 0);
                XYZ pnt2 = new XYZ(1, 0, 0);
                XYZ pnt3 = new XYZ(1, 1, 0);
                XYZ pnt4 = new XYZ(0, 1, 0);
                XYZ pnt5 = new 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);

                XYZ pnt6 = new XYZ(0.5, 0, 0);
                XYZ pnt7 = new XYZ(1, 0.5, 0);
                XYZ pnt8 = new XYZ(0.5, 1, 0);
                XYZ pnt9 = new 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 bottomProfile = document.Application.Create.NewCurveLoopsProfile(arrarr1);
                SweepProfile topProfile = document.Application.Create.NewCurveLoopsProfile(arrarr2);

                XYZ pnt10 = new XYZ(5, 0, 0);
                XYZ pnt11 = new XYZ(0, 20, 0);
                Curve curve = Line.CreateBound(pnt10, pnt11);

                // 在这里创建矩形放样融合
                newSweptBlend = document.FamilyCreate.NewSweptBlend(true, curve, sketchPlane, bottomProfile, topProfile);
                if (null != newSweptBlend)
                {
                    // m移到适当的地方
                    XYZ transPoint1 = new XYZ(11, 32, 0);
                    ElementTransformUtils.MoveElement(document, newSweptBlend.Id, transPoint1);
                }
                else
                {
                    throw new Exception("Failed to create new SweptBlend.");
                }
            }
            else
            {
                throw new Exception("Please open a Family document before invoking this command.");
            }
            return newSweptBlend;

        }

方法仅做参考,大家可以根据自己的需要进行调整。

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值