.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

eGeneralModelingFailure when do a Union operation to two region.

2 REPLIES 2
Reply
Message 1 of 3
bom842218
244 Views, 2 Replies

eGeneralModelingFailure when do a Union operation to two region.

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!

Labels (3)
2 REPLIES 2
Message 2 of 3
_gile
in reply to: bom842218

Hi,

The error is neither due to your code nor to the API.

Trying to Union the regions with the native command also fails.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3
bom842218
in reply to: _gile

Thanks for your explanation. I'm wondering what kind of situation would it be unable to Union. is there some specific scnearios that's not able to Union/Subtract/Intersect ?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report