Revit二次开发学习笔记之体量族或自适应族的放样融合

REVIT体量环境或自适应族环境下的放样

从所周知,在Rviet一般族中其放样方法为:Sweep NewSweep(bool isSolid,ReferenceArray path,SweepProfile profile, int profile Location Curve Index,ProfilePlaneLocation profilePlaneLocation),而在体量环境下则采用Form NewSweptBlendForm()方法。该方法可放样可融合(应该叫放样融合),我自己写了一个放样融合命令。直接上代码:

 public class SweepCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidco = commandData.Application.ActiveUIDocument;
            Document familyDoc = uidco.Document;

            //【1】创建放样路径path
            Line line_P = Line.CreateBound(new XYZ(0, 0, 0), new XYZ(1000 / 304.8, 0, 0));

            //【2】创建要放样的轮廓
            //圆弧的创建需要(草图平面,草图平面与Y轴平行)
            Arc arc1 = Arc.Create(Plane.CreateByNormalAndOrigin(XYZ.BasisX , new XYZ(0, 0, 0)), 50 / 304.8,0, Math.PI*2);
            Arc arc2 = Arc.Create(Plane.CreateByNormalAndOrigin(XYZ.BasisX, new XYZ(1000/304.8, 0, 0)), 100 / 304.8, 0, Math.PI*2);
            Curve c1 = arc1 as Curve;
            Curve c2 = arc2 as Curve;
          
            //【3】将上述创建的辅助线化为模型线
            using (Transaction t1 = new Transaction(familyDoc, "CreateSweep"))
            {
                t1.Start();
                ModelCurve modelCurve_P = familyDoc.FamilyCreate.NewModelCurve(line_P, SketchPlane.Create(familyDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ , new XYZ(0, 0, 0))));//原来写的是
                //ModelCurve modelCurve_P = familyDoc.FamilyCreate.NewModelCurve(line_P, SketchPlane.Create(familyDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisX , new XYZ(0, 0, 0))));
                ModelCurve modelCurve1 = familyDoc.FamilyCreate.NewModelCurve(c1, SketchPlane.Create(familyDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisX, new XYZ(0, 0, 0))));

                ModelCurve modelCurve2 = familyDoc.FamilyCreate.NewModelCurve(c2, SketchPlane.Create(familyDoc, Plane.CreateByNormalAndOrigin(XYZ.BasisX, new XYZ(1000/304.8, 0, 0))));

                ReferenceArray refArr_P = new ReferenceArray();
                ReferenceArray refArr1 = new ReferenceArray();
                ReferenceArray refArr2 = new ReferenceArray();
                ReferenceArrayArray refArrArr = new ReferenceArrayArray();

                refArr_P.Append(modelCurve_P.GeometryCurve.Reference);
                refArr1.Append(modelCurve1.GeometryCurve.Reference);
                refArr2.Append(modelCurve2.GeometryCurve.Reference);
                refArrArr.Append(refArr1);
                refArrArr.Append(refArr2);

                familyDoc.FamilyCreate.NewSweptBlendForm(true, refArr_P, refArrArr);
                t1.Commit();
            }
            return Result.Succeeded;
        }
    }

在尝试的过程中,遇到了一点问题,分享一下。由于我们只是做一个命令(放样或放样融合),一旦模型线有问题,常常调试得不到解决,大多情况下是模型线数据或草图的问题。在做的过程中报了个错误Revit二次开发学习笔记之体量族或自适应族的放样融合_第1张图片
说是曲线必须在一个平面内,查找了好一会发现,放样路径生成模型线是,定义平面写错(我写了XYZ.Basisx)。最后运行成功Revit二次开发学习笔记之体量族或自适应族的放样融合_第2张图片
欢迎批评指正!!年轻人,加油!!

你可能感兴趣的:(revit二次开发)