Create Spline from multiple line, curve, arc segments

dwightduronidavy
Enthusiast

Create Spline from multiple line, curve, arc segments

dwightduronidavy
Enthusiast
Enthusiast

Dear all,

I am currently working on the below Revit 2024 macro which does the following:

1. prompt user to select multiple lines and or curve and or arcs
2. convert combined segments into a Spline

However, it keeps generating the following error:
No overload for method 'Create' takes 2 arguments (CS1501) - C:\ProgramData\Autodesk\Revit\Macros\2024\Revit\AppHookup\CreateSplineFromMultipleSegments\Source\CreateSplineFromMultipleSegments\ThisApplication.cs:74,41

Any help would be very much appreciated.


MACRO:

using System;
using System.Collections.Generic;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

namespace CreateSplineFromMultipleSegments
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("055979FA-2219-4A0B-A529-E8C0885531D5")]
public partial class ThisApplication
{
private void Module_Startup(object sender, EventArgs e) { }

private void Module_Shutdown(object sender, EventArgs e) { }

#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion

public void CreateSpline()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;

try
{
// Prompt user to select multiple elements
IList<Reference> selectedElements = sel.PickObjects(ObjectType.Element, "Select multiple segments (lines, arcs, splines).");
if (selectedElements == null || selectedElements.Count == 0)
{
TaskDialog.Show("Error", "No elements selected.");
return;
}

// Collect all the points from the selected elements
List<XYZ> points = new List<XYZ>();

foreach (Reference reference in selectedElements)
{
Element element = doc.GetElement(reference);
LocationCurve locationCurve = element.Location as LocationCurve;

if (locationCurve != null)
{
Curve curve = locationCurve.Curve;
if (curve != null)
{
points.Add(curve.GetEndPoint(0));
points.Add(curve.GetEndPoint(1));
}
}
}

// Ensure unique points and maintain order
points = RemoveDuplicatePoints(points);

if (points.Count < 2)
{
TaskDialog.Show("Error", "Not enough points to create a spline. At least two unique points are required.");
return;
}

// Create the spline from the collected points
using (Transaction tx = new Transaction(doc, "Create Spline"))
{
tx.Start();

NurbSpline spline = NurbSpline.Create(points, false);
SketchPlane sketchPlane = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero));
ModelCurve modelCurve = doc.Create.NewModelCurve(spline, sketchPlane);

tx.Commit();
}

TaskDialog.Show("Success", String.Format("Spline created successfully from {0} segments.", selectedElements.Count));
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
TaskDialog.Show("Cancelled", "Operation cancelled by the user.");
}
catch (Exception ex)
{
TaskDialog.Show("Error", String.Format("An error occurred: {0}", ex.Message));
}
}

private List<XYZ> RemoveDuplicatePoints(List<XYZ> points)
{
List<XYZ> uniquePoints = new List<XYZ>();

foreach (XYZ point in points)
{
if (!uniquePoints.Exists(p => p.IsAlmostEqualTo(point)))
{
uniquePoints.Add(point);
}
}

return uniquePoints;
}
}
}

0 Likes
Reply
150 Views
2 Replies
Replies (2)

scgq425
Advocate
Advocate

Hi @dwightduronidavy :

in revit 2024 dont have NurbSpline with two arguments .

you can read this website and try again .

NurbSpline Members 

scgq425_0-1733836352747.png

 

LanHui Xu
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

dwightduronidavy
Enthusiast
Enthusiast

Thank you @scgq425 , will do some research 

0 Likes