Add multiple objects from python to Rhino in one step?

Hi
In Rhino8 Script Editor python 3:
from an excel file : I’m reading point coordinates, creating vertices, creating triangular surfaces.
I have around 30,000 triangles
df_meshinfo_minimal[‘Triangle_Brep’] is a column in the dataframe containing the rhino objects generated through RhinoGeometry.NurbsSurface.CreateFromCorners

Next I want to write these into Rhino, which I’m doing like this:

for brep in df_meshinfo_minimal['Triangle_Brep']:
    if brep:
        sc.doc.Objects.AddSurface(brep)
rs.Redraw()

Is there a faster way to do this?

TIA

Don’t redraw after each item added, that will slow things down tremendously. Only redraw once at the end when you are finished,

1 Like

It looks to me that the OPs script has already done that.

If all them triangles happen to be created so that Rhino can join them, then joining before adding to the document might be faster.

Also I don’t know how much faster , but it definitely will be at least a little faster to add the breps directly to the Rhino document instead of calling another script to do it for you.

1 Like

Hi @Aditya_Kaushik,

Do you really need 30,000 NURBS surfaces? Perhaps a mesh with triangular faces would make more sense?

– Dale

I haven’t done meshes in Rhino Gh before, let me take a look what that means.

for what I’m doing, I could use a couple of nurbs surface by combining these triangles based on some parameter. I was going to use lunchbox join brep tool to do that once everything was in Rhino.

some of these triangles in the same category are offset from each other. The brep join tool (lunchbox), joins as much as geometry as possible and returns the minimum number of breps. I would want the two breps in blue and yellow highlights
Is there a way to do this in Rhino?

image

Hi @Aditya_Kaushik,

A Brep with 30,000 faces is hideous. You should look into making a mesh.

Were can I get your data? Excel?

– Dale

@dale
I have attached an excerpt of data,
sampleinfo.csv (67.0 KB)

It has two category labels, each of which contain several hundred mesh labels, each mesh label is associated with 3 vertices, whose coordinates are identified as V1, V2, V3. My goal is to get the least number of breps/ surfaces possible for each category label.

Thanks

Hi @Aditya_Kaushik,

Here is a C# script for Rhino 8 that will read your csv file into Rhino as a series of meshes.

Aditya.cs (4.6 KB)

To view and/or edit, use Rhino 8’s ScriptEditor command.

– Dale