Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Failed to create arbitrary profile for sweep

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
nam_vt
945 Views, 4 Replies

Failed to create arbitrary profile for sweep

I want to create a sweep in a family document with an arbitrary profile base on input.
However, I have receiving inconsistent result: sometime it succeeds, sometime it fails.
I don't know why since the profiles I tried to create are very simple as you can see below.
The error I received can vary from time to time if I change the values of the arcs and lines
but not the general shapes.
What are the causes for the problem and how to fix it?
 
private CurveArray CreatecustomCoverProfile(double offset) 
{  
    // the following code worked  
    // Arc arc1 = Arc.Create(new XYZ(0, 0, 0), 5, Math.PI / 2, Math.PI * 3 / 2, XYZ.BasisX, XYZ.BasisY);  
    // Line line = Line.CreateBound(new XYZ(0, 5, 0), new XYZ(0, -5, 0));  
    // CurveArray curveArr = new CurveArray();  
    // curveArr.Append(arc);  
    // curveArr.Append(line);    

    // the following code failed 
    XYZ center1 = new XYZ(0, 0, 0);  
    XYZ center2 = new XYZ(10, 0, 0);  
    Arc arc1 = Arc.Create(center1, 5, Math.PI / 2, Math.PI * 3 / 2, XYZ.BasisX, XYZ.BasisY);  
    Arc arc2 = Arc.Create(center2, 5, Math.PI * 3 / 2, Math.PI * 5 / 2, XYZ.BasisX, XYZ.BasisY);  
    Line line1 = Line.CreateBound(new XYZ(0, 5, 0), new XYZ(10, 5, 0));  
    Line line2 = Line.CreateBound(new XYZ(0, -5, 0), new XYZ(10, -5, 0));  

    CurveArray curveArr = new CurveArray();  
    curveArr.Append(arc1);  
    curveArr.Append(line1);  
    curveArr.Append(arc2);  
    curveArr.Append(line2);  
    return curveArr; 
} 

private bool CreateSweep(Document famDoc) 
{  
    Family family = famDoc?.OwnerFamily;  
    if (null == family)   return false;  
    Collection<XYZ> points = CreateCablePoints();  
    if (points.Count < 2)   
        return false;  

    using (Transaction trans = new Transaction(famDoc, "create cover"))  
    {
        trans.Start();   
        // create profile   
        CurveArrArray arArr = new CurveArrArray();   
        arArr.Append(CreatecustomCoverProfile(0));   
        SweepProfile profile = _rvApp.Create.NewCurveLoopsProfile(arArr);   

        // create path   
        // the path was created from a simple sine-like hermite spline with hardcode control points
        CurveArray path = CreatePath(points);

        // create sketch plane
        Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero);
        SketchPlane pathPlane = SketchPlane.Create(famDoc, plane);
        Sweep cover = famDoc.FamilyCreate.NewSweep(true, path, pathPlane, profile, 0, ProfilePlaneLocation.Start);
        trans.Commit();
    }
    return true; 
}
 
4 REPLIES 4
Message 2 of 5
aignatovich
in reply to: nam_vt

It seems, that the problem is in your curve loop. First arc ends at the point with coordinates: (0, -5, 0), but then you append a line, that starts from (0, 5, 0). Try to replace this:

    curveArr.Append(arc1);  
    curveArr.Append(line1);  ->     curveArr.Append(line2);
    curveArr.Append(arc2);  
    curveArr.Append(line2);  ->     curveArr.Append(line1);
Message 3 of 5
nam_vt
in reply to: aignatovich

Thanks for the suggestion, but I believe that is not the case. I tried it with the "working" code and it works with either of my line 's direction. The "failed" code still does not work no matter what order I put my curves in the curve loop, or whether the curves directions conform the curve loop 's direction.

Message 4 of 5
nam_vt
in reply to: nam_vt

I just figure out why my code did not work: The size of the profile I created is too big that when it is swept along the path, the sweep did intersect itself. Thus the error occurred.
However, I wonder if there is a simple way for us dev to detect the problem programmatically instead of just manually calculate the sweep and scratch our heads until we come a cross this possibility randomly. An evaluate method when create sweep or an exception throw when commit to database would be nice. For now, I only receive unintuitive error message of Revit.

Message 5 of 5
JimJia
in reply to: nam_vt

I am sorry to say that there is currently no API access to this functionality. 

 

You can post your wish idea here to vote it: http://forums.autodesk.com/t5/revit-ideas/idb-p/302/tab/most-recent

 

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report