2

I have just started working with Revit API for a short time and been scratching my head with this problem. 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

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.

Thế Long
  • 516
  • 7
  • 19

1 Answers1

0

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. 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. It could be a tedious work in case you need many family of the same type but with difference in number of adaptive point.

Thế Long
  • 516
  • 7
  • 19