2

我刚刚开始使用 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 创建家庭文档扫描的示例代码,同样的错误仍然会发生。

4

1 回答 1

0

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

我想知道是什么导致了这种差异?

如果您密集使用族或族复杂,加载一个将获得良好的性能和更简单的代码编写。

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

于 2018-08-25T08:27:31.587 回答