CreateFromLines - Errors and unexpected result

Greetings,

we have a Rhino 6 plugin developed for internal purposes and we are thinking on upgrading it to Rhino 8 (used version 8.9.24194.18121 for this), of which we already have some licenses. Everything has worked fine on the migration, except the Mesh.CreateFromLine function which seems to behave worse than in the previous version, where it gave us no errors.

Below you have the result on Rhino 6 and on Rhino 8. As you can see the Rhino 6 version works fine but the Rhino 8 one is not able to discern the faces correctly and creates a mesh that is incorrect. Both have been created using the same model and the same code.


I haven’t been able to create a mesh using the whole wireframe model, because it gives me the following error every time I run the command.

I don’t know at this point if it’s an issue with the function itself or if it’s my model which is at fault.
It would be great if someone could offer some assistance on this issue.

I have attached the 3dm file to this post and the code used is this:

List<CurveObject> selectedLines = new List<CurveObject>();
foreach (RhinoObject obj in doc.Objects.GetSelectedObjects(false, false))
{
    if (obj.ObjectType.Equals(ObjectType.Curve))
    {
        selectedLines.Add((CurveObject)obj);
    }
}

List<Curve> curves = new List<Curve>();
foreach (CurveObject curve in selectedLines)
{
    curves.Add((Curve)curve.Geometry);
}

if (curves.Count == 0 || curves.Exists(c => c == null || !c.IsValid))
{
    MessageBox.Show("Error - No lines selected or no valid lines found");
}
else {
    Mesh m = Mesh.CreateFromLines(curves.ToArray(), 5, 0.5);
    doc.Objects.AddMesh(m);
}

return Result.Success;

I believe this is part of WeaverBird as stated on this post, so I mention you @piac just in case, if not excuse me.

Thank you all beforehand

SimpleMesh.3dm (203.6 KB)

Hi @Iker_Montoya,

This seems to work in Rhino 8 SR10:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var rc = RhinoGet.GetMultipleObjects("Select lines", false, ObjectType.Curve, out var objrefs);
  if (rc != Result.Success)
    return rc;

  var curves = new List<Curve>(objrefs.Length);
  foreach (var objref in objrefs)
    curves.Add(objref.Curve());

  var mesh = Mesh.CreateFromLines(curves.ToArray(), 5, doc.ModelAbsoluteTolerance);
  if (null != mesh)
  {
    mesh.Unweld(Math.PI / 3, true);
    doc.Objects.Add(mesh);
  }

  doc.Views.Redraw();

  return Result.Success;
}

What am I missing?

– Dale

there is also a similar topic

did this got fixed ?

Hi @dale ,

thanks for the quick reply.

Yesterday I updated the Rhinocommon version to 8.10.24226.13001 and didn´t work.

Your code works for the whole model indeed, and mine doesn´t, still there are some instances in which even with your code the method doesn´t work as intended.

For the whole model, it seems that the error is in the selection method that I used, because the error still appears whenever I try to create the mesh on the whole model, yet when I use the selection code you provided works.

Is there anything wrong with the way I used to select the lines? I reviewed the result of both selection methods and I cannot see anything, both are lists of LineCurve objects with the same attribute values and without invalid objects.

As for the other tests I made, the function seems to be having issues with the faces when certain parts of the model are selected even though it works fine for the whole model.
partialTest2
partialTest

On other cases, just as I described in the first post the error occurs and is not able to generate the mesh, for example with the selections I made below on the provided model.

partialTestError

partialTestError2

And thanks @Tom_P , I already read the other topics about errors on the CreateFromLines method, yet I didn’t find anything in them that could help solve the problem I had.

Hi @Iker_Montoya,

Please provide us with everything we need to reproduce the “doesn’t work”, including full source, geometry, and instructions on how to reproduce.

Thanks,

– Dale

Hi @dale ,

For the development I use Microsoft Visual Studio Professional 2022 (64-bit) - Version 17.10.5, and the RhinoCommon and RhinoWindows version 8.10.24226.13001.

In the atached source in which I only have one command called MyTest. I have also attached the model, in it I have specified the lines that cause the errors in the layers that you see in the image below.

The “Wrong Mesh” layers have line selections that produce incorrect meshes and the ones named “Error Example” are lines that upon executing the command throw an error.

As for the instructions to reproduce just select the lines via “Select Objects” in the layers’ context menu and execute the MyTest command.

I hope I have given you everything needed to reproduce the error, and sorry if I haven`t been able to explain myself clearly.

RhinoPluginTest.7z (2.5 MB)
SimpleMesh.3dm (199.0 KB)

I did not look at the PluginTest but just checked what the
_meshFromLines command does.
did you notice those little lines ? - red in the screenshot.

after _join and _simplify the affected (Poly) Lines, the command seems to work.

_selShort 600 will find 46 curves

but i do not see the reason why Error example 1 and 2 fail.

Hi @Tom_P ,

Yes, those lines are there because we need them. The purpose of using the CreateFromLines function to get a mesh is not the mesh itself but the faces contained on it. Those faces should be delimited by the lines we define, in order to calculate the areas of the faces connected vertices and edges.

I attached another model in which the same error occurs, I have used the function with maxFaceValence of 4. Selecting the whole model raises an error and the selection of parts of the model do not create the mesh as it did in Rhino 6.



SimpleMesh2.3dm (84.5 KB)

RH-89837 Mesh.CreateFromLines in Rhino 8 produces unexpected results