Revit API无法在通用模型自适应系列文档中创建新扫描

时间:2018-07-12 09:06:00

标签: c# visual-studio-2017 revit-api

我刚刚开始使用Revit API了很短的时间,并且一直为这个问题挠头。我想使用“通用模型自适应”族模板创建一个包含实体形式的族。但是,似乎我无法使用

在家庭文档中创建扫描
Autodesk.Revit.Creation.FamilyItemFactory.NewSweep()

随着我不断收到以下异常:

Autodesk.Revit.Exceptions.InvalidOperationException
The attempted operation is not permitted in this type of family.

此错误的原因是什么?即使我一直在处理新创建的家庭文件,为什么仍不允许进行该操作? 这是我的代码:

// sweepPath is a CurveByPoints instance.
if (null != sweepPath)
            {
                acTrans.Start("Cable");
                // create a circle as bottom shape for the cable
                IList<XYZ> points = sweepPath.GeometryCurve.Tessellate();
                XYZ center = points[0];
                Plane workingPlane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, center);
                Arc bottomShape = Arc.Create(workingPlane, _radius, 0, 2 * Math.PI);

                // create profile
                CurveArray curveArray = new CurveArray();
                curveArray.Append(bottomShape);
                CurveArrArray arrArray = new CurveArrArray();
                arrArray.Append(curveArray);
                SweepProfile profile = _rvApp.Create.NewCurveLoopsProfile(arrArray) as SweepProfile;

                // create path
                XYZ sweepPathDirection = points[1] - points[0];
                double angle = sweepPathDirection.AngleTo(XYZ.BasisZ);
                XYZ direction = sweepPathDirection.CrossProduct(XYZ.BasisZ);
                Line axis = Line.CreateUnbound(center, direction);
                ElementTransformUtils.RotateElement(familydoc, sweepPath.Id, axis, angle);
                CurveArray path = new CurveArray();
                path.Append(sweepPath.GeometryCurve);

                // create sketch plane
                Plane plane = Plane.CreateByNormalAndOrigin(new XYZ(10, 0, 0), refPointArray.get_Item(0).Position);
                SketchPlane pathPlane = SketchPlane.Create(familydoc, plane);

                // create the cable
                // Sweep sweep = familydoc.FamilyCreate.NewSweep(true, curveArray, pathPlane, profile, 0, ProfilePlaneLocation.Start);
                ReferenceArray refArray = new ReferenceArray();
                refArray.Append(sweepPath.GeometryCurve.Reference);
                Sweep sweep = familydoc.FamilyCreate.NewSweep(true, refArray, profile, 0, ProfilePlaneLocation.Start);
                acTrans.Commit();
            }

编辑1:我首先认为家庭文档没有激活,所以我尝试了

Application.OpenDocumentFile(file_path_for_my_family_document);

但是没有成功。即使我尝试使用示例代码从SDK创建家庭文档中的清除代码,也始终发生相同的错误。

1 个答案:

答案 0 :(得分:0)

事实证明这不是一个好主意,因为revit api不支持在自适应家族文档中特别创建和稳定的创建扫描。我不知道其背后的原因,但这是无法实现的,即使我可以在普通的通用系列文档中做同样的事情。我必须加载现有的适应性家庭。

我想知道是什么原因引起的?

如果您频繁使用该系列,或者该系列很复杂,那么加载一个系列将获得良好的性能,并且编写的代码也更加简单。

如果仅在非常有限的情况下使用简单的家庭,从api创建一个家庭是一个很好的解决方案。如果您需要许多相同类型的家庭,但适应点的数量不同,这可能是一件繁琐的工作。