Hi. I met some problem when I trying to do the Region.BooleanOperation. I wrote a command to prompt user to select multiple regions, and I join (union) them into a region. below is my code for doing this :
using AutoCadExtension.ExtensionMethod;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using AcadRegion = Autodesk.AutoCAD.DatabaseServices.Region;
using System;
using System.Linq;
[CommandMethod("JoinRegions")]
public void JoinRegions()
{
try
{
var doc = AcadApplication.DocumentManager.MdiActiveDocument;
var editor = doc.Editor;
var db = doc.Database;
var pso = new PromptSelectionOptions()
{
MessageForAdding = "select regions",
MessageForRemoval = "unselect regions"
};
var psr = editor.GetSelection(pso);
if (psr.Status != PromptStatus.OK) return;
using (var tr = doc.TransactionManager.StartTransaction())
{
var selectedObjIds = psr.Value.GetObjectIds().Where(objId => objId.ObjectClass.DxfName == "REGION");
var selectedRegions = selectedObjIds.Select(objId => objId.GetObject(OpenMode.ForWrite) as AcadRegion).ToList();
AcadRegion region = selectedRegions[0];
for (int i = 1; i < selectedRegions.Count; i++)
{
region.BooleanOperation(BooleanOperationType.BoolUnite, selectedRegions[i]); //->eGeneralModelingFailure
}
tr.Commit();
}
}
catch (System.Exception ex)
{
AcadApplication.ShowAlertDialog("Unhandled Exception:\n" + ex.Message);
return;
}
}
but in some cases, the BooleanOperation() method would throw an eGeneralModelingFailure exception. if I move some region a bit. the operation can be succeed again. there's no more information/message thrown. just can't figure out what's the reason of this exception. can anyone give some tips? thanks!
the attached file is the region I tested. I know there might be many possible reasons. so this file may help reproduce my problem. thanks for any help!
Can't find what you're looking for? Ask the community or share your knowledge.