Hi,
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");
return;
}
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:
- 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?
- 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
- 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:
Lofting.gh (10.5 KB)
Thank you,
Regards
Ralph