Lofting and divide surface error in C# scripting


I’m having an issue in my C# script and don’t quit understand the problem. the component should loft curves input and divide the surface created from the loft function.

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

using System.IO;
using System.Linq;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.Runtime.InteropServices;
using Rhino.DocObjects;
using Rhino.Collections;
using GH_IO;
using GH_IO.Serialization;

 private void RunScript(List<Curve> G, int U, int V, bool Close, bool transpose, int pathDims, ref object bList, ref object divisionPointsTree)
    var breps = Brep.CreateFromLoft(G, Point3d.Unset, Point3d.Unset, LoftType.Normal, Close);
    if (1 == breps.Length)
      bList = breps[0].Surfaces[0];

    bList = bList.Where(x => x != null).ToList();

    if(bList == null){
      Print("Empty bList");
    if((U < 2) || (V < 2 )){Print(" "); Print("Invalid U/V values");return;}

    PathDims = pathDims;

    DivideBrepFaceList(transpose, bList, U, V);
    divisionPointsTree = divPtsTree;  //>> out


  // <Custom additional code> 
  static double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

  public DataTree<Point3d?> divPtsTree;
  public int PathDims;

  public void DivideBrepFaceList(bool transpose, List <Brep> bList, int U, int V){

    divPtsTree = new DataTree<Point3d?>();

    for(int surfIndex = 0; surfIndex < bList.Count;surfIndex++){
      Brep brep = bList[surfIndex];
      BrepFace face = brep.Faces[0];
      bool IsSurface = face.IsSurface;

      Surface surf = face.UnderlyingSurface();
      if(transpose)surf = surf.Transpose();

      double w; double h; surf.GetSurfaceSize(out w, out h);
      double uStep = w / (double) U; double vStep = h / (double) V;

      surf.SetDomain(0, new Interval(0, w));
      surf.SetDomain(1, new Interval(0, h));

      for(int u = 0; u <= U;u++){
        Curve isoU = surf.IsoCurve(1, u * uStep);
        for(int v = 0; v <= V;v++){
          Point3d p = isoU.PointAt(v * vStep);
          GH_Path path = (PathDims == 2) ? new GH_Path(surfIndex, u) : new GH_Path(surfIndex, u, v);
          if(!IsSurface && !FaceContains(p, face))  divPtsTree.Add(null, path);
          else divPtsTree.Add(p, path);

  public bool FaceContains(Point3d p, BrepFace face){
    double u,v; face.ClosestPoint(p, out u, out v);
    if(face.IsPointOnFace(u, v) != PointFaceRelation.Exterior) return true; else return false;

I’m receiving several error messages:

  1. Error (CS1061): ‘object’ does not contain a definition for ‘Where’ and no extension method ‘Where’ accepting a first argument of type ‘object’ could be found (are you missing a using directive or an assembly reference?
  2. Error (CS1502): The best overloaded method match for ‘Script_Instance.DivideBrepFaceList(bool, System.Collections.Generic.List<Rhino.Geometry.Brep>, int, int)’ has some invalid arguments
  3. Error (CS1503): Argument 2: cannot convert from ‘object’ to ‘System.Collections.Generic.List<Rhino.Geometry.Brep>’

I’ve been having this problem for a while now and can’t seem to find the correct solution.
PS: I’m new to C# scripting

find the gh script here: (10.5 KB)

Thank you,

See attached (8.1 KB)

BTW: Using a close option for the Loft is tricky (you’ll need various checks in order to avoid bananas out of bananas [general case]). Not to mention the actions needed if the Surface is closed in U/V .

BTW: The nullable Tree is a good thing … but the Loft is unlikely to yeild a BrepFace anyway: Suggestion: forget curves, use BrepFaces Lists.

BTW: Add an option for quad or tri pieces (Surfaces [slow] or Meshes [fast]) according various “patterns” (that’s as a challenge).

1 Like

Hey @PeterFotiadis,

Thank you so much for both the help and the script !
You’re a savior !!
As for the comments, i will definitely make sure to apply them as soon as i become more proficient in C#

Things to do:

  1. Working with BrepFaces (Curves have no big meaning - unless you want to add a 1st C# that prepares your stuff) … mastermind a way to get “even” (i.e. proportional - to Sizes- so to speak) U/V divisions based on some user option:

  2. Provide options for what to get (inside/outside plus rules to accept a piece: case quad/tri pieces):

  1. If pieces are required provide output options: (i.e. Surfaces or Meshes).
  2. Take care of Surfs closed in U/V (or both: deal with singularity - see Spheres).
1 Like


If i were to face any new problems along the way would you care to guide me through them ?
It would be nice to learn from an expert in the field.

Post (or PM) the potential issues and have faith to the right Side.

1 Like