Add Ngonstomesh Rhinoscript method?

Hi - I’m looking for an easy to way to perform the following: for convex closed solids (polysurfaces) made up of planar faces I would like to run the mesh method, but produce meshes that are essentially one-to-one. This end result would yield a structured mesh for each object wherein I would have access to its vertices in order along with their coordinates -> essentially what I’d like to get is a node and element list that e.g. FEM software require: the node list contains all mesh nodes and their coordinates, while the element list lists each face and its nodes which correspond to the node list. Although I believe I can achieve this once the mesh is complete in Rhino, the issue is that even with the following settings for meshing (Array(0, 0, 0, 10000, 0, 0, 0, False, False, True, False)), I still get co-planar triangular faces. The only way to merge these co-planar faces quickly without looking at face normals etc that I can think of is to use “AddNgonsToMesh”, which doesn’t seem to be available as a method. Scripting it in via a command doesn’t seem to be viable as it would require user selection for each object. Is there any way to get at this method in Rhinoscript or is there a more convenient way of achieving my goal?

AddNgonsToMesh does not require user input other then selecting the mesh. It automagically merges all co-planar faces to nGons

Perhaps I wasn’t clear: using the command requires selection of a mesh. How do I script this in with _SelLast if the “AddNgonsToMesh” command stops the script for user selection? Doing this for e.g. 10000 polysurfaces is not ideal --> why I asked for help in the first place.

Can you post one of your polysurfaces as an example? Maybe also a corresponding mesh to see what is your desired outcome. This should be pretty easy in python and sinde rhinoscriptsyntax was designed after RhinoScript should be also possible in it.

If you upload an example i can make a prototype

Here’s a 3DM with two sets of solids on separate layers and their respective meshes, on separate layers. That’s the sort of meshes that I’m looking for - using default meshing options will produce extra triangulations for some of the polysurface faces. AddNgons is an easy way to merge the co-planar triangulations, but this was performed manually.Solid_w_shell.3dm (340.3 KB)

This python script works on your given example: (1.7 KB)

if you are not sure how to run python scripts here is the info page for it:

Sadly to convert this to RhinoScript someone else would need to come in as I’m not fluent in that language.

Let me know if this works / helps :slight_smile:

Perfect thanks - you even built in the planar condition that is necessary, many many thanks! I’ll build on this foundation - time to get to grips with Python, I’ve only used it for a couple scripts intermittently and I seem to turn to VB too easily when given the chance…

One last question: it looks like you’re using Rhinocommon references in the script - if I wanted to be able to apply this to e.g. extrusions, are the methods available in “”? Or how do I identify other methods easily in Rhinocommon?

I make extensive use of the documentation tree inside of the Rhino Python editor:

But also a lot of it comes down to googling, f.e. rhinocommon mesh from brep leads me to the Mesh.CreateFromBrep method…

For extrusions you can convert them to breps by calling myExtrusion.ToBrep()

See this revised example: (2.0 KB)

Brilliant, thanks - this helps a lot!!

Ran into a hiccup - how does the syntax work for setting e.g. the individual properties of the meshingparameters, seeing as I can’t seem to able set multiple properties via a set array prior to setting the parameters as in VB - see below? Your script currently uses the Default property and I’d prefer to force it manual settings?

arrMPP = Array(0, 0, 0, 10000, 0, 0, 0, False, False, True, False)
arrMP = Rhino.MeshParameters(0, arrMPP)

You can create a MeshingParameters instance from scratch:

The easiest way would be to set the settings once via the rhino UI and call

The other way is to create a new instance of meshingParameters and set all properties inside your code

That’s what I’d been looking at but I couldn’t wrap my head around how the syntax works with multiple properties when referencing Rhino common - even the example in “” wasn’t particularly helpful. If I wanted to set everything as 0 and False, apart from MinimumEdgeLength = 10000 and SimplePlanes = True, how do you create the instance? I’ll have to read up on the use of Rhino common after this, but with your example I’ve got a good head-start on the syntax.

This should work:

    # create meshing parameters
    meshParam = Rhino.Geometry.MeshingParameters(0, 10000)
    meshParam.GridAspectRatio = 0
    meshParam.RefineGrid = False

you can then reference the meshParam instance inside of the static Meshing function:

        mesh.Append(Rhino.Geometry.Mesh.CreateFromBrep(brep, meshParam))

Got it thanks again - compared to VB a separate line for each property setting is a little tedious but on the other hand Python combined with Common is so much more powerful and at times also less tedious in addition to being pretty efficient.


More generally you may find this script useful if there is a rhinoscriptsyntax method equivalent to what you are trying to do with Rhinocommon

Thanks Graham - I’ll have to give this a go. In the meantime, how do I access the MeshFaceList when it’s under Rhino.Geometry.Collections? I can’t use “meshfc = Rhino.Geometry.Collections.MeshFaceList()” as this apparently has no public constructor. I’m sure this is dead simple if I have an existing mesh in my document but I’m a complete novice with Rhinocommon :man_facepalming:

Hmm not sure - would Mesh.Faces work for you?

Sheesh - can’t believe I missed that, thanks :see_no_evil:

Hey Lando - how would you get at the ObjectId’s if in the “brep” loop of the objects? I can’t figure out how to get at the active brep id in the loop - the goal is to get the original layer name and index (layer order) of the original polysurfaces (breps&extrusions) in the document, prior to meshing, carrying it over to the resulting meshes.