Grasshopper

algorithmic modeling for Rhino

Rewriting Grasshopper Definitions in C# - questions with the output

I am currently in the process of rewriting some components in my Grasshopper definitions in C#. The definitions that involve the primitive types (i.e. int, double, lists, etc) are fairly straight forward, however, those involving non-primitive types such as meshes, breps, or anything involving Rhino-specific planes in general, I am having a bit of trouble. An example would be above, where the input would be boundary, width count, and height count, with the output being mesh coordinates (non-primitive types) and area (which is a double). 

What type of libraries would I be using in C# for this type of type output? An example in code for reference would help me a lot. Thank you very much!

P.S. A more specific question would be, how do certain definitions in Grasshopper take inputs that involve a string like this "Mesh (V: 1302 F: 1196)"? That's the output of the above definition.

The above example would look like a String, but specifically, they are coordinates. How does inputs read that as?

Views: 989

Replies to This Discussion

Hi Jacky,

the string "Mesh (V: 1302 F: 1196)" is just what you get when you ask a Mesh to describe itself. Obviously it does not carry enough information to represent the entire mesh, it only lists the number of vertices and faces.

Grasshopper uses RhinoCommon for most of its geometric needs. Meshes are Rhino.Geometry.Mesh, rectangles are Rhino.Geometry.Rectangle3d

RhinoCommon namespaces are already imported in the C# component so you can just use Mesh and Rectangle3d (and Curve, and NurbsCurve, and Line, and Point3d, and Brep, and and and) directly.

--

David Rutten

david@mcneel.com

Tirol, Austria

You should use Mesh.CreateFromPlane for this. You can find all RhinoCommon pages here: http://4.rhino3d.com/5/rhinocommon/

I'll assume you meant Rectangle3d boundary instead of int boundary.

public static Mesh returnMesh(Rectangle3d boundary, int width, int height)

{

  return Mesh.CreateFromPlane(boundary.Plane, boundary.X, boundary.Y, width, height);

}

Rectangle3d has an Area property so you don't have to calculate the area of the mesh.

--

David Rutten

david@mcneel.com

Tirol, Austria

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service