简体   繁体   English

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

[英]Revit API Can not create new sweep in generic model adaptive family document

I have just started working with Revit API for a short time and been scratching my head with this problem. 我刚刚开始使用Revit API了很短的时间,并且一直为这个问题挠头。 I want to create a family containing a solid form using "generic model adaptive" family template. 我想使用“通用模型自适应”族模板创建一个包含实体形式的族。 However, it seems like I can not create a sweep in the family document using 但是,似乎我无法使用

Autodesk.Revit.Creation.FamilyItemFactory.NewSweep()

as I keep receiving the following exception: 因为我不断收到以下异常:

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

What are the reasons for this error? 此错误的原因是什么? Why is the operation not permitted even though I have been working on the newly created family document? 即使我一直在处理新创建的家庭文件,为什么仍不允许进行该操作? Here is my code: 这是我的代码:

// 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();
            }

Edit 1: I first thought that the family document is not activated, thus I tried 编辑1:我首先认为家庭文件未激活,所以我尝试了

Application.OpenDocumentFile(file_path_for_my_family_document);

but it didn't work out. 但没有成功。 The same error keeps happening even when I tried the sample code for creating a sweep in family document from the SDK. 即使我尝试了从SDK创建家庭文档扫描的示例代码时,仍然发生相同的错误。

This turned out to be a bad idea because revit api does not support create sweep in particular and solid in general in an adaptive family document. 事实证明这是一个坏主意,因为revit api不支持在自适应系列文档中创建特别是实体扫描。 I don't know the reason behind this but it is un-achievable even though I can do the same thing in a normal generic family document. 我不知道其背后的原因,但这是无法实现的,即使我可以在普通的通用系列文档中做同样的事情。 I have to load an existing adaptive family instead. 我必须加载现有的适应性家庭。

I wonder what causes the difference? 我想知道是什么原因造成的?

If you use the family intensively or the family is complicated, loading one will make good performance and much more simple code to write. 如果您频繁使用该系列,或者该系列很复杂,则加载一个系列将获得良好的性能,并且编写的代码也更加简单。

If you only use a simple family in a very limited situation, create one from api is a good solution. 如果仅在非常有限的情况下使用简单的家庭,从api创建一个家庭是一个很好的解决方案。 It could be a tedious work in case you need many family of the same type but with difference in number of adaptive point. 如果您需要许多相同类型的家庭,但适应点的数量不同,这可能是一件繁琐的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM