Fixing Bad Objects

How to find and (hopefully) fix bad objects created by Rhino, or by importing from other programs

I’ve got a bad object. Why did that happen and how do I fix it?

What is a bad (invalid) object?

“Bad” objects in Rhino are ones that either violate certain NURBS rules, or have a structural problem. In theory, Rhino does not produce bad objects, but in practice, it is possible and does happen periodically. Once you know how to deal with them, they don’t usually take too much to fix. Most often, the bad objects are surfaces, but bad curves also happen occasionally as well.

How do I know if I've got one?

The simplest way to find bad objects is to use the command SelBadObjects (Analyze>Diagnostics>Select Bad Objects). All invalid objects will be selected. But a polysurface may be bad if it contains only one bad surface. You can figure out which one by using the command ExtractBadSrf (not in the menus), which will extract the bad surfaces and select them. There is a useful command in Rhino called CheckNewObjects, which turns on checking in the background and checks all objects as they are created or imported. This way you know immediately when there’s a problem.

Why are these objects considered bad and how were they created?

Well, there are many technical explanations. With surface objects, often it is the structure of the trim curve that is bad. It can have one or more segments that are microscopic and this causes problems. Other times a surface can be bad because it has either two or more rows of control points on top of each other, or has a zero length in one direction (a collapsed edge). This situation is easy to produce in Rhino V3: make a vertical plane or line and then project it to the Cplane from the Top View. The object now has zero length in one direction and will be considered bad. In Rhino V4, this type of operation has been disallowed in certain cases, so that you will not get a bad object. The command will simply fail and you will get an error message. Yet, it is still possible to produce bad objects in V4.

Why might a surface trim curve be bad? You probably didn’t intentionally make it so. Bad objects often show up after using Join (or some other command that also joins objects, like Booleans). When joining objects, Rhino often needs to split edges and adjust trim curves. In certain situations parts of these split edges can end up being microscopic. Or the adjustment of the trim curve goes wrong and all of a sudden Bing!! you have a bad object. (By the way, when I say “microscopic” I mean smaller than your absolute tolerance. Objects that are smaller than that generally have no business in your file and will cause problems.)

Bad objects on import/export

Importing geometry from other programs can also produce bad objects. If you are running CheckNewObjects, while a file is importing you will get a message if and when an invalid object has been created. You need to click OK to acknowledge each one. If there are many, this can be annoying. You can turn the command off and restart it after the import is done.

It is important to understand that the imported objects were likely not considered bad in the originating program. Every program has its own way of creating and checking geometry, and those may not be the same as how Rhino goes about it. On top of that, exchanging data between programs that have different formats requires at least one translation and sometimes two (via a neutral format such as IGES). Translation problems can cause bad objects, depending on the quality of the import/export functions. Rhino will also produce objects that it does not consider bad, but are flagged as bad by other programs.

Phantom surfaces

Why can't I see my bad object?

Occasionally, Rhino produces surfaces that are bad, but you can't see them. Literally, they are invisible! (They are invisible because no render mesh was able to be produced to display them.) They are sometimes referred to as phantom surfaces. Phantom surfaces can cause files to act oddly, for example a ZoomExtents that doesn't work correctly because the invisible surface is out in space and the Zoom command is taking it into account.

These can usually be selected with SelBadObjects, and the best thing is to simply use Delete to get rid of them. Often they can't be fixed. Sometimes, Delete won't work. If that happens, try Ctrl+X to cut them from the file. If you cannot select them in any other way, you can also try this: Zoom extents, window select everything and use Hide. Then try a Ctrl+A. Usually this selects everything in the file, even objects that are unselectable any other way. If you see on the command line that an object is selected, use What to verify that it is indeed your bad object (it will say “invalid”), then just delete it and show all again.

Bad meshes

If a polygon mesh object rings up as bad, use CheckMesh to see a more detailed report of what is wrong with it. This command tells you a good deal about what can be fixed, and you may find the commands you need among the offerings in the Mesh menu, under mesh Edit tools and mesh repair tools. Some useful commands are:

ExtractDuplicateMeshFaces

ExtractNonManifoldMeshEdges

CullDegenerateMeshFaces

UnifyMeshNormals

OK, How do I fix bad curves and surfaces?

Bad polycurves are most often fixed by just exploding and rejoining. Otherwise, look for microscopic segments included in the curve and eliminate those. If that still doesn't fix things, it may be that something is really wrong with the NURBS knot structure of the curve, and it requires more advanced investigation and reconstruction.

My strategy for dealing with bad surfaces due to trim curves follows. Before starting, determine which are the bad surfaces and hide everything else temporarily (you may need to run ExtractBadSrf as above).

1. First, I usually run the command RebuildEdges on all bad objects. This may fix some. It more or less restores the edges of a surface to the state they were before joining. But it also means that the surface might no longer join up to its neighbors, or that joining might make it go bad again. But it does work OK in some cases. If some surfaces are fixed (use SelBadObjects/Invert), hide those. Sometimes running ShrinkSrf on bad surfaces also helps.

2. Use the Untrim command with the keep trim objects option selected (otherwise known as DetachTrim) on the first bad surface, then, while the trim curve is still selected, use Trim to retrim the surface. Has this fixed the surface? If so, good, hide it. If not, leave it and run the same procedure on all other bad surfaces one at a time. Hide all that go good.

3. If any bad objects are left, run DetachTrim on them again. Explode the resulting trim curve and look for micro segments in the curve somewhere. This is the most common case of bad trims. Look at how many component curves the trim curve has. Often there will be a suspicious number, i.e. what looks like it should be a rectangle says 5 curves not 4. Somewhere in there is a micro curve that is messing things up. Often it's near a corner. Try window selecting near the ends of your trim curve segments. Or, use the command SelShortCrv and set a small value. If you find some microsegments, delete them and rejoin the trim curves into a closed loop. Retrim the surface with it. This usually fixes pretty much everything that isn’t fixed by other methods.

4. Last, try unhiding everything (Show), and see if you can join all up without having objects go bad again. If all joins up well and no bad objects, great! If not, then it’s generally because Join is trying to force things together that don’t fit correctly. In that case you have to analyze the surfaces that are going bad and the relation with their neighbors to try and find out what doesn’t fit and why. This can sometimes take some pretty close looking and head scratching…

Note: The above methodology is for dealing with surfaces with bad trim curves. It won’t help surfaces with collapsed edges or stacked rows of control points. Those need to be dealt with by other methods such as knot removal or just plain reconstruction. Surfaces with collapsed edges are easy to spot – the display looks like a curve, but in Properties it says it’s a surface. In general just delete these.