Automate meshing process

I am writing an optimization program and I need to automate the meshing process. I am using Rhino 5 and trying to write a python script. to call externally and run rhino with some parametric function to draw my geometry. However, I am struggling with getting a function to use to select the object I want to mesh. All the examples I have seen so require me to use getObjet. which will break the automation process. I need help to fix this urgently. Below is the code I am using. I need help. Thank you

rhinoFloater.py (2.6 KB)

You can always iterate the document’s object table and find/search for the object you want to mesh.

– Dale

Thanks for the prompt response. I was really hoping for such a quick response. I will try that out. Hopefully, I will be able to resolve it with the reference you provided.

I am still at loss as to how to find the object ID. This is the first time I am trying to script to draw with Rhino. Is there a way to assign an ID so that I don’t have to search for it? Please, could you also kindly help me take a lot at the script file to know If I am doing the right thing. My intention is to construct a floater and do a surface mesh for a Boundary Element Method code for frequency domain analysis.

Hi @infoafonja,

Something like this will work:

Guid obj_id = ...

RhinoObject rh_obj = doc.Objects.FindId(obj_id);
if (null != rh_obj)
{
  // todo...
}

– Dale

Thanks, this works. I think the final challenge now is that after selecting the object and passing it through the code I found online for meshing polysurface using the Brep method. I get an error that my object is a Brepobject and not a Brep.
that is the main challenge now. Not being able to create a surface mesh.

Here is an example:

Guid obj_id = ...

RhinoObject rh_obj = doc.Objects.FindId(obj_id);
if (null != rh_obj)
{
  Brep brep = rh_obj.Geometry as Brep;
  if (null != brep)
  {
    MeshingParameters mp = MeshingParameters.Default;
    Mesh[] meshes = Mesh.CreateFromBrep(brep, mp);
    if (null != meshes && meshes.Length > 0)
    {
      Mesh mesh = new Mesh();
      foreach (Mesh m in meshes)
        mesh.Append(m);

      // todo...
    }
  }
}

There are more examples in the Developer Samples repository.

– Dale

Thanks, Dale for your help. I am using Rhino 5 and I could not find doc.Objects.FindId in its library, It seems it is something new. I could see Find in the library but not FindId
I have no luck yet. I had even tried to use VB and not rhino python still on a dead end.

If you are still using Rhino 5, then just use ObjectTable.Find.

– Dale

I am completely clueless now. I must be doing something wrong and I can’t figure it out. I am quite new to all the languages used in scripting Rhino. I am also unsure where in my code I will need to insert the line you sent to me. I tried to use VB all over from the start and now I can’t even get past creating a surface because I get an error that, type mismatch parameter.

Option Explicit
'Script written by <insert name>
'Script copyrighted by <insert company name>
'Script version Friday, March 19, 2021 11:29:53 AM
Dim Draft, Height, B, L, R, h, k, Za, Xb, H1, Xa, Zb, alphaP, R1, R2, Xp, Zp, xmid, zmid
Dim  Arc1, Arc2, Arc3, line1, Pline, Surface1, ExtrudePath, Extruder, LatestObject
Call Main()
Sub Main()
	Draft = 5
	Height = 25
	B = 23
	L = 46
	R = L / 2
	h = 0.6
	k = 0.8
	Za = 0
	Xb = 0
	H1 = h * R
	Xa = k * R
	Zb = R * (1 - 2 * h - 2 * k + h ^ 2 + 2 * h * k) / (2 - 2 * h - 2 * k)
	alphaP = Rhino.ToDegrees(Atn(Xa / Zb))
	R1 = R - Xa
	R2 = Zb + H1
	Xp = R2 * Sin(Rhino.ToRadians(alphaP))
	Zp = Zb - R2 * Cos(Rhino.ToRadians(alphaP))
	xmid = (R + Xp) / 2
	zmid = 0 - Sqr(R1 ^ 2 - ((xmid - Xa) ^ 2))
	
	Arc1 = Rhino.AddArc3Pt(Array(-R, 0, 0), Array(-Xp, 0, zp), Array(-xmid, 0, zmid))
	Arc2 = Rhino.AddArc3Pt(Array(-Xp, 0, Zp), Array(Xp, 0, zp), Array(0, 0, -H1))
	Arc3 = Rhino.AddArc3Pt(Array(Xp, 0, Zp), Array(R, 0, 0), Array(xmid, 0, zmid))
	line1 = Rhino.AddLine(Array(-R, 0, 0), Array(R, 0, 0))
	ExtrudePath = Rhino.AddLine(Array(0, 0, 0), Array(0, B / 2, 0))
	Pline = Rhino.JoinCurves(Array(Arc1, Arc2, Arc3, line1))
	Surface1 = Rhino.AddPlanarSrf(Pline)
	Extruder = Rhino.ExtrudeCurve(Pline, ExtrudePath)
		
End Sub

rhinoFloater.py (3.1 KB) TestRhinoScript2.rvb (1.3 KB)

I’ve moved this to a new topic, since it has nothing to do with the original one.

Okay, I will more careful next time to ensure that topics are related.

I was able to finally solve the problem but through another means as I could not figure out what was going on. What I did was to use Grasshopper to create the model and the mesh. Then I created a python script to run to call grasshopper and automate it.
Thanks for the time and effort.