Revit 2026 API - document.Create.NewDetailCurve(view, spline) return null while Element is created

Revit 2026 API - document.Create.NewDetailCurve(view, spline) return null while Element is created

corentin216
Community Visitor Community Visitor
129 Views
2 Replies
Message 1 of 3

Revit 2026 API - document.Create.NewDetailCurve(view, spline) return null while Element is created

corentin216
Community Visitor
Community Visitor
 
So I've been using the Revit 2026 API ( and .NET ) to make QoL stuff in an addIn.

I wanted to create some Bezier Curves (HermitSplines) and store the newly created element for later use.

Here is the function I use :

 
        public DetailCurve CreateBezierCurve(Document document, List<XYZ> points, XYZ tangent0, XYZ tangent3)
        {
            DetailCurve result;
            var view = document.ActiveView;

            HermiteSpline spline = HermiteSpline.Create(
                points,
                false,
                new HermiteSplineTangents()
                { 
                    StartTangent = tangent0,
                    EndTangent = tangent3
                }
            );

            using (Transaction tx = new Transaction(document, "Create Bezier Curve"))
            {
                tx.Start();
                result = document.Create.NewDetailCurve(view, spline);
                tx.Commit();
            }

            return result;
        }

The official api info and the IDE helper tab state that the output is indeed a DetailCurve.

It also state that it can return null if a crash appears internally. however I do get the curve created in my file and no sign of any error.

 

I wonder if this is some bug in the API, or a mistake in the documentation. I could not find anything on that subject.

Any help or info is welcome. Thanks

 

PS: I know I could find that newly created curve in other ways but it is definitly not as clean as the intended way.

 

For instance the said curve after creation :

Sans titre.png

 

0 Likes
130 Views
2 Replies
Replies (2)
Message 2 of 3

ctm_mka
Collaborator
Collaborator

instead of forcing it to be a Detailcurve, (which if i'm reading correctly is the issue?) try adding it to a ElementId collection using a DocumentChangedEventArgs event. Then, after committing, _doc.getelement from that collection, and return that instead. something like this:

//in your main method:
 List<ElementId> ElemIdCol = new List<ElementId>();
uiapp.Application.DocumentChanged += new EventHandler<DocumentChangedEventArgs>(OnElemCreation);
CreateBezierCurve()
var thecurve = ElemIdCol.Select(x=> doc.GetElement(x)).FirstOrDefault();

 private void OnElemCreation(object sender, DocumentChangedEventArgs e) 
 {
     ElemIdCol.AddRange(e.GetAddedElementIds());
 }

 

0 Likes
Message 3 of 3

corentin216
Community Visitor
Community Visitor

I guess that works I'll try to do something similar for now, Thanks !

But still I find it strange that a function like this one

DetailCurve NewDetailCurve(View view, Curve geometryCurve);

returns null while creating the curve in revit and not giving any information about an internal error or mistake...

could that be some kind of bug of revit API?

0 Likes