Grasshopper

algorithmic modeling for Rhino

Hey All...
I'm fiddling with C# in grasshopper to try and make a "shelling" script component.
The idea is to make a simple loop that runs through a collection of surfaces, and for each offsets it, lofts each side and joins them as a Brep.
And sadly, I find that I have a problem already even if my code is no more than 3 lines ATM. There seems to be an overload issue with my input in the "new OnNurbsSurface" part. (the input is a single surface from a Surface component in GH)


bool RunScript(OnSurface inSurface, double inDistance)
{
OnNurbsSurface Srf = new OnNurbsSurface(inSurface);
Srf.Offset(inDistance, 0.0);
A = Srf;

}

the errors are:
Error: The best overloaded method match for 'RMA.OpenNURBS.OnNurbsSurface.OnNurbsSurface(RMA.OpenNURBS.IOnBezierSurface)' has some invalid arguments (line 71)
Error: Argument '1': cannot convert from 'RMA.OpenNURBS.OnSurface' to 'RMA.OpenNURBS.IOnBezierSurface' (line 71)

any help appriciated.

Views: 414

Replies to This Discussion

When you get a surface into a scripting component it is a "generic" OnSurface. Even though most surfaces that you'll deal with are derived from the OnSurface class, that doesn't mean that if you have an OnSurface that it will fit interchangeably in those "sub classes". So, in order to get a nurbs surface you have to convert it some how. Typically you can try and cast it, but in this case that won't work (neither OnSurface nor OnNurbsSurface expose a cast function). So the other option is see if OnSurface exposes a method that will allow us to extract the nurbs surface we're looking for. Luckily it does, so you'd have something that looks like this... x is the scripting input....

OnNurbsSurface myNURBSsrf;
myNURBSsrf = x.NurbsSurface();
//continue with what you're doing
Yay.. thats great.. I did think it had to do with something like this...
I have been scripting GC for years, but are somehow missing some fundamentals such as "cast"... I might look that up ;-)
Seems like grasshopper C# scripting is more object oriented or is it just me?!

anyway, it works with this syntax, thanks Damien

bool RunScript(OnSurface inSurface, double inDistance)
{
OnNurbsSurface iSrf1;
iSrf1 = inSurface.NurbsSurface();

OnSurface iSrf2 = iSrf1.Offset(inDistance, 0);

A = iSrf2;
}
ok, I have to ask again...
In trying to get the abovementioned Brep from a single untrimmed surface i need to loft the edges to close the figure.
In Gc I would have written something like this to get the vertices of the surface, and with a loop or something create the four edges:

for (int i = 0; i < numberofedgesonsurface; i++)
{
myEdgeSurf[i] = new BsplineSurface.FromVertices(mySurface1.Vertices[i], mySurface1.Vertices[i+1], mySurface2.Vertices[i+1], mySurface2.Vertices[i]);
}

So, can I similarly 'get' to the subcomponents of my surface to use either the edges or the vertices to create the edge surfaces?

any tips?!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service