Mesh from Points

Hi

I have been using a C component to create a mesh from points.

image

However the speed appears erratic. Sometimes I get a rapid response (less than 5 seconds) but sometimes it can take 2 minutes to create a mesh from about 12000 points.
The content of the component is as follows.

using Rhino;
using Rhino.Geometry;
using Rhino.DocObjects;
using Rhino.Collections;

using GH_IO;
using GH_IO.Serialization;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Linq;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Runtime.InteropServices;

///


/// This class will be instantiated on demand by the Script component.
///

public class Script_Instance : GH_ScriptInstance
{
#region Utility functions
/// Print a String to the [Out] Parameter of the Script component.
/// String to print.
private void Print(string text) { __out.Add(text); }
/// Print a formatted String to the [Out] Parameter of the Script component.
/// String format.
/// Formatting parameters.
private void Print(string format, params object args) { __out.Add(string.Format(format, args)); }
/// Print useful information about an object instance to the [Out] Parameter of the Script component.
/// Object instance to parse.
private void Reflect(object obj) { __out.Add(GH_ScriptComponentUtilities.ReflectType_CS(obj)); }
/// Print the signatures of all the overloads of a specific method to the [Out] Parameter of the Script component.
/// Object instance to parse.
private void Reflect(object obj, string method_name) { __out.Add(GH_ScriptComponentUtilities.ReflectType_CS(obj, method_name)); }
#endregion

#region Members
///

Gets the current Rhino document.
private RhinoDoc RhinoDocument;
/// Gets the Grasshopper document that owns this script.
private GH_Document GrasshopperDocument;
/// Gets the Grasshopper script component that owns this script.
private IGH_Component Component;
///
/// Gets the current iteration count. The first call to RunScript() is associated with Iteration==0.
/// Any subsequent call within the same solution will increment the Iteration count.
///

private int Iteration;
#endregion

///


/// This procedure contains the user code. Input parameters are provided as regular arguments,
/// Output parameters as ref arguments. You don’t have to assign output parameters,
/// they will have a default value.
///

private void RunScript(bool run, List pts, ref object A)
{
//your code here…

if (!run) { return;}
if (pts.Count < 3) { return; }

//Unselect all objects
doc.Objects.UnselectAll();

//Then, bake the objects and remember all the IDs so we can delete them properly
List<Guid> pointIDs = new List<Guid>(pts.Count);

for (int i = 0; i < pts.Count; i++){
  if (pts[i].IsValid) { pointIDs.Add(doc.Objects.AddPoint(pts[i])); }
}

//Now run the MeshFromPoints command
doc.Objects.Select(pointIDs);

if (RhinoApp.RunScript("-_MeshfromPoints _Enter", false))
{
  //If the script was successfully run, search for the most recently added object
  Rhino.DocObjects.RhinoObject obj = doc.Objects.MostRecentObject();
  A = obj.Geometry.Duplicate();
  doc.Objects.Delete(obj, true);
}

//Now delete the points
doc.Objects.Delete(pointIDs, true);

}

//

// </Custom additional code>

private List __err = new List(); //Do not modify this list directly.
private List __out = new List(); //Do not modify this list directly.
private RhinoDoc doc = RhinoDoc.ActiveDoc; //Legacy field.
private IGH_ActiveObject owner; //Legacy field.
private int runCount; //Legacy field.

}

Would be grateful if anybody can shed a light on why the variance in response when
using this component.

William