CreateSolid with tolerance

I would like to create solids from “almost” perfectly intersecting surfaces. “CreateSolid” does not include tolerances. So, I would like to specify a tolerance for the gaps, below which a gap is neglected. For example, if I am handling objects in the range of meters and there are two surfaces with a gap of 5 mm, this gap is neglected and I get a solid anyway. How can I do this?

You can change document absolute tolerance from Options.
Or:

import Rhino
from scriptcontext import doc

def CreateSolid():
    go = Rhino.Input.Custom.GetObject()
    go.SetCommandPrompt("Select intersecting surfaces and polysurfaces to automatically trim and join into a closed polysurface")

    tolOption = Rhino.Input.Custom.OptionDouble(doc.ModelAbsoluteTolerance, 0, 100.0)
    delOption = Rhino.Input.Custom.OptionToggle(True, "No", "Yes")

    go.AddOptionDouble("tolerance", tolOption)
    go.AddOptionToggle("DeleteInput", delOption)
    while True:
        rc = go.GetMultiple(1, 0)
        if rc == Rhino.Input.GetResult.Option:
            continue
        break

    breps = [go.Object(i).Brep() for i in range(go.ObjectCount)]
    if len(breps) > 0:
        breps = Rhino.Geometry.Brep.CreateSolid(breps, tolOption.CurrentValue)
        if len(breps) > 0:
            for brep in breps:
                doc.Objects.AddBrep(brep)
            if delOption.CurrentValue:
                for objref in go.Objects():
                    doc.Objects.Delete(objref, True)
        else:
            Rhino.RhinoApp.WriteLine("Unable to create solid.")
    return Rhino.Commands.Result.Success


if __name__ == "__main__":
    CreateSolid()

CreateSolidWithTolerance.py (1.2 KB)

Thank you Mahdiyar. Sorry, but it doesn’t work neither with absolute tolerance from the options, nor with your py-script. See the exable attached. The upper surfaces has a gap of 5 cm, the tolerance is set to 0.1 units (i.e. 10 cm).SolidTest02.3dm (51.2 KB)

The gap between the surfaces is 0.05. You need to have a tolerance of more than twice that value for it to succeed - i.e. anything over 0.10 works (native command, didn’t test the script).

Doing this is not a real good idea though, if you tighten the tolerances again, explode the object and rebuild the edges, it will no longer join.

Changing the tolerance does not extend the surfaces - it simply allows surface edges to be moved away from their natural position in order to be joinable. The modified edges will then be out of tolerance if the file tolerances are made tighter again.

2 Likes

It is the other way around. The gap has be less than twice the absolute tolerance for Join, etc to work.

An alternative to changing the tolerance for Join is JoinEdge which ignores the tolerance. However forcing joins with edges further apart then the absolute tolerance frequently causes problems later on.

A better alternative is to extend all the surfaces so that they overlap and then use CreateSolid.

1 Like

I was talking about the file tolerance setting here, as the subject was how to override the file tolerance to get CreateSolid to work.

Yes, that’s why I added the mention that the procedure of overriding the tolerance was not a good idea generally.

What is the “file tolerance setting”? I’m only aware of the “absolute tolerance” setting:
Options > Document Properties > Units > Units and tolerances > Absolute tolerance

A quick experiment shows that CreateSolid works with a set of surfaces with a maximum gap of 0.158 if the absolute tolerance is set to 0.1 but not if the absolute tolerance is set to 0.05.

I use the two terms more or less interchangeably - as the absolute tolerance is set at the file level.

In the file the OP supplied above where the gap measures 0.05m (in the closest, vertical direction), CreateSolid still fails using the absolute tolerance already set in the file at 0.1, but setting it to 0.101 allows it to succeed.

Helvetosaur and David Cockey, thank you for your feedback. I see that the best thing would be to avoid changing tolerance and to extend all the surfaces so that they overlap, and then use CreateSolid. Now, how can I quickly identify surfaces which have gaps, in order to extend them?

I guess you could simply select all and call Intersect - wherever curves don’t show up where you think there should be an intersection will be where the gaps are.

Ok, thanks.

Here’s a quickly hacked together experimental script that tries to extend surfaces in order to be able to create a solid…

CreateSolidTolerance.py (2.8 KB)

Currently limited:

  • Will only extend planar and cylindrical surfaces (separately or within polysurfaces)
  • Only gives a result if one unique solid is able to be created
  • If a valid result is found, all selected input objects are deleted (even if not involved in the solid)

Some of the above issues can be addressed with more work. It should work OK with most planar-surfaced objects, for the rest, well, I’m sure there will be lots of quirks. FWIW…

Dear Helvetosaur, thank you. I tested the py-script with the example (SolidTest02.3dm), but it didn’t work. I get the attached warning. What did I wrong?Warning

Odd, it works here on your file. Hmm, are you working in V6? If you are on V5, it looks like you could get that message as the ShrinkSurfaceToEdge method did not exist in V5…

After installing the updates, it worked. Thanks.

OK, that method might have been added sometime during the course of V6, I don’t know when. Let me know if the script is actually useful to you…

Dear all
I am working at a new project. Again, I cannot create a solid from different surfaces.

I am looking for a tool (or a Rhino plugin) that works quick and dirty. This tool should have following inputs:
_Different surfaces that more or less form one or more closed volumes
_A point inside, from which a sort of voxel can grow up. With this point I can specify the unique volume which I am interested in.
_The lenght of the voxel side
_A cube that specifies the maximum extend of the voxel that grows

Starting this tool the algorithm lets the voxels grow from the inside point in all directions until the voxels touch a surface. If there is a hole in the surfaces, the voxel can grow through the hole only if it is smaller than the hole. But it can not grow more than the maximum extend cube. When finished the growing, the tool builds up many triangles that have the outer voxels vertices as tringale points. So, all these triangles are forming a closed volume (solid).

Who knows a sort of tool that works similarly?

Rhino does not use “voxels” or similar. A solid in Rhino is simply a closed surface or polysurface.

Yes, a solid is a closed polysurface. And this is what I want to generate with the tool. At the end, the tool builds up many triangles that have the outer voxels vertices as triangle points. So, all these triangles are forming a closed polysurface. The voxels are merely intended as algorithm elements.
Do you know a sort of tool that works similarly?

Nothing that works similarly, but you could consider the alternative approach of shrink wrapping. try searching the forum for Daniel Piper’s shrinkwrap wip.

But as you haven’t posted any details of your problem, or an example of your geometry, I am left wondering why extendsrf and trim don’t cut it for you?