Grasshopper

algorithmic modeling for Rhino

That's the error I get when I try to load a custom component where I want to operate over a surface. 

 

I have tried to load the surface as Surface, NurbsSurface and BrepFace.

 

Code goes this way:

 

protected override void SolveInstance(IGH_DataAccess DA) {           

Brep myBrep= null;                                  

if (DA.GetData<Brep>(0, ref myBrep))           

{               

int U = 0;               

int V = 0;

 

if (!DA.GetData(1, ref U)) { return; }               

if (!DA.GetData(2, ref V)) { return; }

 

Point3d[,] colec = new Point3d[U + 1, V + 1];

double paramU = 0.0;               

double paramV = 0.0;

BrepFace mySrf = myBrep.Faces[0];

mySrf.SetDomain(0, new Interval(0.0,1.0));                   

mySrf.SetDomain(1, new Interval(0.0,1.0));                                       

for (int j = 0; j <= U; j++){

paramU = j * (1.0 / U);                                                      

for (int k = 0; k <= V; k++) { 
                           paramV = k * (1.0 / V);
                           colec[j, k] = new Point3d((mySrf.PointAt(paramU, paramV).X), (mySrf.PointAt(paramU, paramV).Y), (mySrf.PointAt(paramU, paramV).Z));                          }

                    }

 

.....

 

 

I have been able to reproduce this inside a C# Script component without problems. Any clue?

 

Thank you!

Views: 1994

Replies to This Discussion

Hi Roberto,

 

GH_Surface wraps around Breps, no Surfaces or NurbsSurfaces or BrepFaces. It only allows Breps with a single face, but it's a full brep none-the-less.

 

However, GH_Surface defines data casts to both Rhino.Geometry.Surface, Rhino.Geometry.Brep and Rhino.Geometry.BrepFace, so if you ask a Surface parameter for any of these types, it should give you what you ask for (NurbsSurface won't work).

 

I just tested this with GH_Surface, Surface, Brep and BrepFace and they all work.

 

However the error message seems to indicate you've got a piece of data which is not a GH_Surface. This error is now thrown inside the SolveInstance method, but rather when the Parameter collects data from it's sources. It should also tell you what types of data failed to convert, but you didn't include that in your post.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thank you David, it seems we get close to my problem. Below you see the complete code. I attached a Screenshot of the error.

My script is as simple as constructing quads over a given surface.

I am passing a list of NurbsSurface to the output.

 

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)       

{           

pManager.Register_SurfaceParam("Srf", "S", "Srf to Quad");            pManager.Register_IntegerParam("U", "U", "U divisons",10);            pManager.Register_IntegerParam("V", "V", "V divisions",10);
}

protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)      

{           

pManager.Register_SurfaceParam("Quads", "Q", "Quads");        

}

 

protected override void SolveInstance(IGH_DataAccess DA)       

{       

Surface mySrf= null; 

if (DA.GetData<Surface>(0, ref mySrf))           

{                

int U = 0;

int V = 0;               

if (!DA.GetData(1, ref U)) { return; }               

if (!DA.GetData(2, ref V)) { return; }                 

Point3d[,] colec = new Point3d[U + 1, V + 1];     

 

double paramU = 0.0;                

double paramV = 0.0;   

 

mySrf.SetDomain(0, new Interval(0.0,1.0));                    

mySrf.SetDomain(1, new Interval(0.0,1.0));                                        

 

for (int j = 0; j <= U; j++){


                       paramU = j * (1.0 / U);                                                       

for (int k = 0; k <= V; k++) {                            

paramV = k * (1.0 / V);                           

colec[j, k] = new Point3d((mySrf.PointAt(paramU, paramV).X),(mySrf.PointAt(paramU, paramV).Y), (mySrf.PointAt(paramU, paramV).Z));                          }                  

}                    

List<NurbsSurface> outQuads = new List<NurbsSurface>();

                    for (int j = 0; j < U; j++){

for (int k = 0; k < V; k++){  

LineCurve line1 = new LineCurve(colec[j, k], colec[j + 1, k]);                            LineCurve line2 = new LineCurve(colec[j, k + 1], colec[j + 1, k + 1]);                             NurbsSurface nurbsSurface = NurbsSurface.CreateRuledSurface(line1, line2);                           

outQuads.Add(nurbsSurface);                        

}                    

}                                    

DA.SetData(0, outQuads);                                    

}

}

 

Thank you very much for your help!!

Attachments:

Ah, the problem is not GetData, it's SetData.

 

you're assigning lists of surfaces to the output parameter, so you should be calling SetDataList instead.

 

DA.SetDataList(0, outQuads);

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

aaaaaaaaaaaaaaaaaaaaaaaa!!!!

If you were a girl and still 1.95m....

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service