Error using FamilyCreate.NewSweep

Error using FamilyCreate.NewSweep

dirk.neethling
Advocate Advocate
1,212 Views
6 Replies
Message 1 of 7

Error using FamilyCreate.NewSweep

dirk.neethling
Advocate
Advocate

Hello,

after successfully creating sweeps in a Project doc, with support from Revitalizer, I decided to try this in a Family doc.

I managed to create the sweep Profile, and transform it so that it is perpendicular to the sweep path, see pic: 

 profile.png

 

In order to call FamilyCreate.NewSweep, I created the following parameters:

path,

pathPlane_l,

sweepProfile_l,

 

 

The path Parameter is a circle as follows:

 

CurveArray path = new CurveArray();

XYZ Center = new XYZ(0,0,0);

double planeRadius = 2d;

Plane plane = new Plane(XYZ.BasisZ, center);

Arc arc1 = Arc.Create(plane, planeRadius, 0.0, Math.PI);

Arc arc2 = Arc.Create(plane, planeRadius, Math.PI, Math.PI * 2);

path.Append(arc1);

path.Append(arc2);

 

 

 

The SketchPlane is as follows:

SketchPlane pathPlane_l = SketchPlane.Create(famDoc, plane);

 

 

 

The sweep Profile is created as follows:

 

var _profilepoints = new List<XYZ>() {

MmToFootPoint(new XYZ(-10,0,0)),

MmToFootPoint(new XYZ(-11.36,-7.7,0)),

MmToFootPoint(new XYZ(-14.15,-10.49,0)),

MmToFootPoint(new XYZ(-13,-16.5,0)),

MmToFootPoint(new XYZ(-11,-16.5,0)),

MmToFootPoint(new XYZ(-10.27,-13.78,0)),

MmToFootPoint(new XYZ(-9.41,-12.5,0)),

MmToFootPoint(new XYZ(-7.95,-12,0)),

MmToFootPoint(new XYZ(-6.49,-12.5,0)),

MmToFootPoint(new XYZ(-5.63,-13.78,0)),

MmToFootPoint(new XYZ(-4.91,-16.5,0)),

MmToFootPoint(new XYZ(-2.91,-16.5,0)),

MmToFootPoint(new XYZ(-2.18,-13.78,0)),

MmToFootPoint(new XYZ(-1.4,-12.5,0)),

MmToFootPoint(new XYZ(0,-12,0)),

MmToFootPoint(new XYZ(1.4,-12.5 ,0)),

MmToFootPoint(new XYZ(2.18,-13.78,0)),

MmToFootPoint(new XYZ(2.91,-16.5,0)),

MmToFootPoint(new XYZ(4.91,-16.5,0)),

MmToFootPoint(new XYZ(5.63,-13.78,0)),

MmToFootPoint(new XYZ(6.49,-12.5,0)),

MmToFootPoint(new XYZ(7.95,-12,0)),

MmToFootPoint(new XYZ(9.41,-12.5,0)),

MmToFootPoint(new XYZ(10.27,-13.78,0)),

MmToFootPoint(new XYZ(11,-16.5,0)),

MmToFootPoint(new XYZ(13,-16.5,0)),

MmToFootPoint(new XYZ(14.15,-10.49,0)),

MmToFootPoint(new XYZ(11.36,-7.7,0)),

MmToFootPoint(new XYZ(10,0,0)),

MmToFootPoint(new XYZ(-10,0,0))

};

profileLoop = new CurveLoop();

for (int i = 0; i < (_profilepoints.Count - 1); i++)

{

Line line = Line.CreateBound(_profilepoints[i], _profilepoints[i + 1]);

profileLoop.Append(line);

}

 

//transform it into the sweep plane

var tangent = initV.Direction.CrossProduct(XYZ.BasisZ);

//translate the profile to the starting point

var startingPointOfSweep = initV.GetEndPoint(0);

Curve curve = profileLoop.First();

var startPointOfProfile = curve.GetEndPoint(0);

var translation = startingPointOfSweep - startPointOfProfile;

var transform = Transform.CreateTranslation(translation);

profileLoop.Transform(transform);

 

//flip the profile vertical around this tangent

transform = Transform.CreateRotationAtPoint(tangent, Math.PI / 2.0, startingPointOfSweep);

profileLoop.Transform(transform);

 

CurveArray arr = new CurveArray();

foreach (var item in profileLoop)

{

arr.Append(item);

start = item.GetEndPoint(0); ;

fin = item.GetEndPoint(1);

var l_ = Creator.CreateModelLine(famDoc, start, fin);

}

curveArrArr.Clear();

curveArrArr.Append(arr);

SweepProfile sweepProfile_l = famDoc.Application.Create.NewCurveLoopsProfile(curveArrArr);

 

 

This call cracks:

Sweep solid = famDoc.FamilyCreate.NewSweep(

true,

path,

pathPlane_l,

sweepProfile_l,

0,

ProfilePlaneLocation.Start);

 

Error message:

{"One of the conditions for the inputs was not satisfied. Consult the documentation for requirements for each argument."} System.Exception {Autodesk.Revit.Exceptions.ArgumentException}

 

 

What am I doing wrong?

Regards,Dirk

 

0 Likes
Accepted solutions (1)
1,213 Views
6 Replies
Replies (6)
Message 2 of 7

FAIR59
Advisor
Advisor

for the newsweep method, you mustn't transform the profile. the curve(s) need to be in the XY-plane.

 

profileType: Autodesk.Revit.DB SweepProfile
The profile of the newly created Sweep. This may contain more than one curve loop or a profile family. The profile must lie in the XY plane, and it will be transformed to the profile plane automatically. Each loop must be a fully closed curve loop and the loops must not intersect. The loop can be a unbound circle or ellipse, but its geometry will be split in two in order to satisfy requirements for sketches used in extrusions.

Message 3 of 7

dirk.neethling
Advocate
Advocate

Hello FAIR59,

thanks for answering.

I generate the Profile as follows, so I assume it is in the XY-plane:

 

var _profilepoints = new List<XYZ>() {

MmToFootPoint(new XYZ(-10,0,0)),

MmToFootPoint(new XYZ(-11.36,-7.7,0)),

MmToFootPoint(new XYZ(-14.15,-10.49,0)),

MmToFootPoint(new XYZ(-13,-16.5,0)),

MmToFootPoint(new XYZ(-11,-16.5,0)),

MmToFootPoint(new XYZ(-10.27,-13.78,0)),

MmToFootPoint(new XYZ(-9.41,-12.5,0)),

MmToFootPoint(new XYZ(-7.95,-12,0)),

MmToFootPoint(new XYZ(-6.49,-12.5,0)),

MmToFootPoint(new XYZ(-5.63,-13.78,0)),

MmToFootPoint(new XYZ(-4.91,-16.5,0)),

MmToFootPoint(new XYZ(-2.91,-16.5,0)),

MmToFootPoint(new XYZ(-2.18,-13.78,0)),

MmToFootPoint(new XYZ(-1.4,-12.5,0)),

MmToFootPoint(new XYZ(0,-12,0)),

MmToFootPoint(new XYZ(1.4,-12.5 ,0)),

MmToFootPoint(new XYZ(2.18,-13.78,0)),

MmToFootPoint(new XYZ(2.91,-16.5,0)),

MmToFootPoint(new XYZ(4.91,-16.5,0)),

MmToFootPoint(new XYZ(5.63,-13.78,0)),

MmToFootPoint(new XYZ(6.49,-12.5,0)),

MmToFootPoint(new XYZ(7.95,-12,0)),

MmToFootPoint(new XYZ(9.41,-12.5,0)),

MmToFootPoint(new XYZ(10.27,-13.78,0)),

MmToFootPoint(new XYZ(11,-16.5,0)),

MmToFootPoint(new XYZ(13,-16.5,0)),

MmToFootPoint(new XYZ(14.15,-10.49,0)),

MmToFootPoint(new XYZ(11.36,-7.7,0)),

MmToFootPoint(new XYZ(10,0,0)),

MmToFootPoint(new XYZ(-10,0,0))

};

 

 

I removed the transform, but the result is still that the Profile is not being swept along the arc

Regards, dirk

 

copyAndTransform2.png

0 Likes
Message 4 of 7

FAIR59
Advisor
Advisor
Accepted solution

hello dirk,

 

i can't find  anything wrong with the pieces of code you provided.

 

possibilities:

  1. check if MmToFootPoint returns a Z-value of 0
  2. the "stick" in your picture shouldn't be part of the profile
  3. in between the pieces of code, do you change something?  ( path, pathPlane_l )

this is my testing code,  (it works in Revit 2016)

 

    public static partial class Extensions
    {
        public static XYZ MmToFootPlanePoint(this Plane plane, UV pt)
        {
            return plane.Origin+ plane.XVec.Multiply(pt.U/304.8)+plane.YVec.Multiply(pt.V/304.8);
        }

    }
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]

    public class Fa_Test : IExternalCommand
    {
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            StringBuilder sb = new StringBuilder();
            try
            {
                Document famDoc = revit.Application.ActiveUIDocument.Document;
                if (!famDoc.IsFamilyDocument) return Result.Failed;
                using (Transaction t3 = new Transaction(famDoc, "test"))
                {

                    t3.Start();
                    CurveArray path = new CurveArray();
                    XYZ Center = new XYZ(0, 0, 0);
                    double planeRadius = 2d;
                    Plane plane = new Plane((XYZ.BasisX+XYZ.BasisZ).Normalize(), Center);
                    Arc arc1 = Arc.Create(plane, planeRadius, 0.0, Math.PI);
                    Arc arc2 = Arc.Create(plane, planeRadius, Math.PI, Math.PI * 2);
                    path.Append(arc1);
                    path.Append(arc2);
                    SketchPlane pathPlane_l = SketchPlane.Create(famDoc, plane);

                    Plane LoopPlane = new Plane(XYZ.BasisZ, Center); 
                    //SketchPlane loopPlane_l = SketchPlane.Create(famDoc, LoopPlane);

                    var _profilepoints = new List<XYZ>() { 
                            LoopPlane. MmToFootPlanePoint(new UV(-10,0)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-11.36,-7.7)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-14.15,-10.49)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-13,-16.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-11,-16.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-10.27,-13.78)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-9.41,-12.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-7.95,-12)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-6.49,-12.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-5.63,-13.78)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-4.91,-16.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-2.91,-16.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-2.18,-13.78)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-1.4,-12.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(0,-12)), 
                            LoopPlane. MmToFootPlanePoint(new UV(1.4,-12.5 )), 
                            LoopPlane. MmToFootPlanePoint(new UV(2.18,-13.78)), 
                            LoopPlane. MmToFootPlanePoint(new UV(2.91,-16.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(4.91,-16.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(5.63,-13.78)), 
                            LoopPlane. MmToFootPlanePoint(new UV(6.49,-12.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(7.95,-12)), 
                            LoopPlane. MmToFootPlanePoint(new UV(9.41,-12.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(10.27,-13.78)), 
                            LoopPlane. MmToFootPlanePoint(new UV(11,-16.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(13,-16.5)), 
                            LoopPlane. MmToFootPlanePoint(new UV(14.15,-10.49)), 
                            LoopPlane. MmToFootPlanePoint(new UV(11.36,-7.7)), 
                            LoopPlane. MmToFootPlanePoint(new UV(10,0)), 
                            LoopPlane. MmToFootPlanePoint(new UV(-10,0))
                    };

                    CurveLoop profileLoop = new CurveLoop();

                    for (int i = 0; i < (_profilepoints.Count - 1); i++)
                    {
                        Line line = Line.CreateBound(_profilepoints[i], _profilepoints[i + 1]);
                        profileLoop.Append(line);
                    }
                    CurveArray arr = new CurveArray();

                    foreach (var item in profileLoop)
                    {

                        arr.Append(item);

                        XYZ start = item.GetEndPoint(0); ;
                        XYZ fin = item.GetEndPoint(1);

                        sb.AppendLine(string.Format("{0}", start));

                        //var l_ = famDoc.FamilyCreate.NewModelCurve(Line.CreateBound(start, fin), loopPlane_l);

                    }

                    CurveArrArray curveArrArr = new CurveArrArray();

                    curveArrArr.Append(arr);

                    SweepProfile sweepProfile_l = famDoc.Application.Create.NewCurveLoopsProfile(curveArrArr);
                    Sweep solid = famDoc.FamilyCreate.NewSweep(true, path, pathPlane_l, sweepProfile_l, 0, ProfilePlaneLocation.Start);
                    t3.Commit();
                }

                TaskDialog.Show("debug", sb.ToString());
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                TaskDialog.Show("catch", ex.ToString());
            }
            return Result.Succeeded;
        }
    }

Message 5 of 7

dirk.neethling
Advocate
Advocate

Hello FAIR59,

 

thanks very much, your solution works fine. I'll use that as an incubator.

Regards, Dirk

0 Likes
Message 6 of 7

dirk.neethling
Advocate
Advocate

One more question: when I use your static class,

    public static partial class Extensions
    {
        public static XYZ MmToFootPlanePoint(this Plane plane, UV pt)
        {
            return plane.Origin + plane.XVec.Multiply(pt.U / 304.8) + plane.YVec.Multiply(pt.V / 304.8);
        }
    }

 

 

I get the following compiler error:

"Error 13 Extension method must be defined in a non-generic static class" 

0 Likes
Message 7 of 7

FAIR59
Advisor
Advisor

the extension class can't be a nested class. You have to define it directly in the namespace.

 

namespace FAIR_Space
{
    public static partial class Extensions
    {
        public static XYZ MmToFootPlanePoint(this Plane plane, UV pt)
        {
            return plane.Origin + plane.XVec.Multiply(pt.U / 304.8) + plane.YVec.Multiply(pt.V / 304.8);
        }

    }

 

 

In this case (profile in XY-plane) the method is a bit of overkill for the profilePoints , and you could use your own method MmToFootPoint, provided that the return XYZ has Z-value =0 

0 Likes