Unable to add BRep object to Doc

Hi!
I’m working on a command that let user choose an existsing BRrep, duplicates it, transform it and, finally, add the duplicated and transformed BRep to the active RhinoDoc.
It used to work fine… Since I’ve found a document containing BReps my command doesn’t work with.
I mean… I can duplicate and transform BReps but I can’t add them to the active RhinoDoc.
Every time I try to do it, using RhinoDoc.Objects.Add(brepGeometry), i get an empty object ID as a result.
Of course i could add those objects to the doc (no locked layers ecc…).
The only thing that looks strange to me is that those BRep objects has their “IsValid” flag set to false.
Do you think this could be the problem?
What does it means to have the “IsValid” flag set to false?
Is there a way to make those objects “valid”?

PS Also Rhino “object details” window tells me that objects are not valid but I’m able to duplicate and transform them using Rhino interface.
Thanks a lot, guys! :slight_smile:

Solved using Brep.Repair()

You can interrogate why an object is invalid using obj.IsValidWithLog(out string error). If it returns false, the string will contain a message why it is invalid.
Also, within Rhino there is the command SelBadObjects, which allows the user to identify invalid objects.

Thanks a lot, @menno! Very useful!