# Model Curve by best fit through points

**URL:** <https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405>\
**Category:** Uncategorized\
**Created:** [December 14, 2023, 3:03pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405 "2023-12-14T15:03:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [December 14, 2023, 3:03pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/1 "2023-12-14T15:03:22Z")

</div>

Hello Dynamo Friends 🙂

I Have 15.000 Points

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/f/efad4a09d3a0fca9b82dd9f52c743acd3602af11.png)

And I want to make a line through them so I used nurbscurve by points.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/8/382a60ea8f1145b8a81a6b56800341bc627f5226.png)

But now I cant create a model curve from the nurbscurve because it is not planar. And I can´t explode it.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/3/33478d01daabd1677ea0296c1c0bcd8c0aab432a.png)

Whatelse can i do to get my model curve? polycurve by points is not giving a good result because it gives only straight lines and no arcs.

Appreciate any advice!

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [December 14, 2023, 3:18pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/2 "2023-12-14T15:18:28Z")

</div>

Results may vary based on your nurbs curve, but `PolyCurve.ByJoinedCurves` will accept nurbs curves. That should at least get you to a PolyCurve which you can begin breaking down as necessary (if necessary).

---

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [December 14, 2023, 6:36pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/4 "2023-12-14T18:36:56Z")

</div>

Hello @Nick_Boyts

I´m afraid that doesn´t work, just getting nurbscurves again:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/2/52bd7873a3dc25b45e4974f5cd8709327d842833.png)

So if there is no obvious method to do this, I´ll try to set up a python code that creates nurbs curves but with planar pieces or something like that.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [December 14, 2023, 7:15pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/5 "2023-12-14T19:15:01Z")

</div>

Well that’s annoying. Yeah, python might be the best option here if you want simplified geometry.

EDIT: Actually it looks like `Curve.ApproximateWithArcAndLineSegments` works on nurbs curves. Again, it may vary depending on how complex your nurbs curve is, but it works for me with a simple case. You’re still probably going to end up with a bunch of smaller segments, but that seems like a given with complex geometry.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 14, 2023, 7:26pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/6 "2023-12-14T19:26:34Z")

</div>

Simple answer: don’t do it this way.

Detailed answer: move into the adaptive or massing environment, convert the points to reference points, and draw a model curve by points. Depending on your Revit version there should be out of the box nodes for each of these steps, but it can be done via Python rather easily as well.

---

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [December 15, 2023, 12:25am UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/7 "2023-12-15T00:25:37Z")

</div>

ok, so such a model line can only exist in a family environment? 😕 My goal was to create a model line in the project environment…thats disappointing. Will have to change many scripts now ^^

Thanks @jacob.small !

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/a/5a138173b73dfc071bdd6f6e2f8fbff517e58a42.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 15, 2023, 12:40am UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/8 "2023-12-15T00:40:03Z")

</div>

> [@gerhard.p](#):
>
> ok, so such a model line can only exist in a family environment? 😕 My goal was to create a model line in the project environment…thats disappointing.

As always, follow this rule:

> **If you can’t do it in the Revit UI, you shouldn’t do it in the Revit API even if it lets you.**

While there are few exceptions to this they are few and far between (so much so that they escape me at the moment - maybe deleting a particular workset?). So when doing automations, I always ask myself two questions. The first is “If I had to draw that curve manually in the Revit, how would I go about it?”

Once I figure that out (often literally writing down the steps), it’s onto question two: “How do I tell the computer to take all of the same steps I just did manually?”

Then I finally launch Dynamo.

---

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [December 15, 2023, 3:39pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/9 "2023-12-15T15:39:53Z")

</div>

That makes perfect sense!

I managed to create a DB.Nurbspline but I can not find it in the adaptive family I´m working in.  
Am I using the right method?

> **[CreateCurve Method (IList(XYZ), IList(Double))](https://www.revitapidocs.com/2023/0ef02fb4-1ef1-6adb-dfb6-680eba6fed62.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/9/c9e5b9c7b8faf1da061f164c71cc9d34bb6dad94.png)

```auto
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument

# The input to this node will be a list of reference points
input_points = IN[0]

revit_points = [XYZ(point.X, point.Y, point.Z) for point in input_points]

# Assuming uniform weights for simplicity. Adjust as necessary.
weights = [1.0 for _ in revit_points]

# Start Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

try:
    # Create a NURBSpline through the reference points
    spline = NurbSpline.CreateCurve(revit_points, weights)

    # Commit the transaction
    TransactionManager.Instance.TransactionTaskDone()
    doc.Regenerate()

    OUT = spline

except Exception as e:
    # Handle exceptions
    TransactionManager.Instance.ForceCloseTransaction()
    OUT = str(e)

```

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 15, 2023, 5:00pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/10 "2023-12-15T17:00:34Z")

</div>

Can you post a DYN with the points, and let me know which Revit year?

---

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [December 15, 2023, 5:49pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/11 "2023-12-15T17:49:06Z")

</div>

Got it 😃  
But as such lines can´t be used for sweeping it´s not what I was looking for, but good to know anyway!

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/d/3d33715bcf60ae9e7c3f1872b10485d8cbf4edec.jpeg)

> **[NewCurveByPoints Method](https://www.revitapidocs.com/2015/40741486-ce16-4aed-fa74-257a36ab7428.htm)**
>
> Online Documentation for Autodesk's Revit API: 2015, 2016, 2017, 2017.1, 2018

```auto
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Get the current document
doc = DocumentManager.Instance.CurrentDBDocument

refPoints = UnwrapElement(IN[0])

# Start a transaction
TransactionManager.Instance.EnsureInTransaction(doc)

try:
    # Create ReferencePointArray and add points to it
    refPointArray = ReferencePointArray()
    for refPoint in refPoints:
        refPointArray.Append(refPoint)

    # Create the curve
    curve = doc.FamilyCreate.NewCurveByPoints(refPointArray)

    # Commit the transaction
    TransactionManager.Instance.TransactionTaskDone()

    OUT = curve

except Exception as e:
    # Handle exceptions
    TransactionManager.Instance.ForceCloseTransaction()
    OUT = str(e)

```

This is the corresponding dynamo node:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/2/b277131060740b073b01deb68237616b0938aa90.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 15, 2023, 6:14pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/12 "2023-12-15T18:14:37Z")

</div>

> [@gerhard.p](#):
>
> But as such lines can´t be used for sweeping it´s not what I was looking for

99% sure you can sweep along this.

Look at hosting an adaptive profile family on the curve, and try sweeping that.

I believe the Dynamo node to host it is something like ‘AdaptiveFamilyByCurveParameter‘ or something along those lines. It’s the other ‘AdaptiveComponent’ constructor in the default library.

After that try to sweep the profile along the line in the UI, and then you can look into building up some Python to perform the loft action.

---

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [December 15, 2023, 7:01pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/13 "2023-12-15T19:01:12Z")

</div>

That works!  
In the UI I can make a freeform:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/3/c3a12aa41bc45d0feff509480175fd0b0c89b02d.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 15, 2023, 7:07pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/14 "2023-12-15T19:07:55Z")

</div>

And so your next task, should you choose to accept it, is to try and implement that node in Python, and then call this method: [NewSweptBlendForm Method](https://www.revitapidocs.com/2024/2a5b308c-ff6a-d29a-2810-ac1d843c4945.htm)

---

<div class="post-metadata">

**Author:** ![gerhard.p](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gerhard.p/32/147675_2.png) [@gerhard.p](https://forum.dynamobim.com/u/gerhard.p)\
**Post date:** [December 15, 2023, 8:20pm UTC](https://forum.dynamobim.com/t/model-curve-by-best-fit-through-points/96405/15 "2023-12-15T20:20:13Z")

</div>

I fail at hosting the profile to the curvebypoints. As all parameter nodes dont work with this curve I tried it with python but still get an error.  
Also tried using 0 or 1 or [0,1] as paramters, do not really know what to use here and always get the same error. DYN attached! Oh and I use Revit 23 and 24.

[Adaptive.dyn](https://forum.dynamobim.com/uploads/short-url/24l1F3rzcpUI78W1uNPdBP0oqvj.dyn) (4.8 MB)  
[Profil\_d20\_adaptive.rfa](https://forum.dynamobim.com/uploads/short-url/jjh8cOtpJJeNGj2Os2xfFqdbm5e.rfa) (432 KB)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/2/52298599136b1989a0a664dd0ff966367fdf527b.png)
