This works for me:
Code:
private static void CheckInference(List<Solid3d> solids, Transaction tr)
{
if (solids.Count < 2)
return;
var owner = (BlockTableRecord)tr.GetObject(solids[0].OwnerId, OpenMode.ForWrite);
for (int i = 0; i < solids.Count - 1; i++)
{
for (int j = i + 1; j < solids.Count; j++)
{
if (solids[i].CheckInterference(solids[j]))
{
using (var solid1 = (Solid3d)solids[i].Clone())
using (var solid2 = (Solid3d)solids[j].Clone())
{
solid1.BooleanOperation(BooleanOperationType.BoolIntersect, solid2);
solid1.ColorIndex = 1;
owner.AppendEntity(solid1);
tr.AddNewlyCreatedDBObject(solid1, true);
}
}
}
}
}
Testing command:
Code:
[CommandMethod("INTERSOLID")]
public static void InterSolid()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
var filter = new SelectionFilter(new[] { new TypedValue(0, "3DSOLID") });
var selection = ed.GetSelection(filter);
if (selection.Status != PromptStatus.OK) return;
using (var tr = db.TransactionManager.StartTransaction())
{
var solids = selection.Value.GetObjectIds()
.Select(id => (Solid3d)tr.GetObject(id, OpenMode.ForRead))
.ToList();
CheckInference(solids, tr);
tr.Commit();
}
}